CentOS6.2下YUM安装MySQL
2013-03-05 22:40
232 查看
用yum安装MySql
打入如下命令:
[root@mysql ~]# yum -y install mysql-server //自动从网上搜索资源并自动下载安装
[root@mysql ~]# chkconfig mysqld on //设置开机启动MySql服务
检查是否为开机启动
打入命令:[root@mysql ~]# chkconfig –list
看到:mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 即表示已设置为开机启动,2、3、4、5为on
启动MySql服务
/etc/rc.d/init.d/mysqld start //从文件启动MySql服务
service mysqld start //以服务名方式启动
MySql初始化环境设置(一)
设置MySQL的root用户设置密码,因为MySQL被安装时,它的root用户时没有设置密码的。
– [root@mysql ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
2. 如上,默认是不需要密码就可以进入数据库操作,下面查看MySQL数据库用户信息
MySql初始化环境设置(二)
打入命令:select user,host,password from mysql.user; //可以看到密码都为空
– +------+-----------+----------+
– | user | host | password |
– +------+-----------+----------+
– | root | localhost | |
– | root | mysql | |
– | root | 127.0.0.1 | |
– | | localhost | |
– | | mysql | |
– +------+-----------+----------+
– 5 rows in set (0.00 sec)
– set password for root@localhost=password(‘123456789’); //设置root用户密码为123456789
MySql初始化环境设置(三)
• 打入命令:select user,host,password from mysql.user; //查看刚设置的密码,可以看到密码已经经过加密处理
– +------+-----------+-------------------------------------------+
– | user | host | password |
– +------+-----------+-------------------------------------------+
– | root | localhost | *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D |
– | root | mysql | |
– | root | 127.0.0.1 | |
– | | localhost | |
– | | mysql | |
– +------+-----------+-------------------------------------------+
– 5 rows in set (0.00 sec)
• 打入exit命令退出数据库连接,测试root密码是否生效
MySql初始化环境设置(四)
• 打入命令:mysql –u root
– ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u root' at line 1
– 弹出图上提示说明刚设置的密码已生效
• 下面通过密码登陆,打入命令:mysql –u root –p //在Enter password后输入刚才设置的密码,看到下面即表示登陆成功
– [root@mysql ~]# mysql -u root -p
– Enter password:
– Welcome to the MySQL monitor. Commands end with ; or \g.
– Your MySQL connection id is 3
– Server version: 5.1.61 Source distribution
– Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
– Oracle is a registered trademark of Oracle Corporation and/or its
– affiliates. Other names may be trademarks of their respective
– owners.
– Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
– mysql>
增删改查语句
• Show databases; //查看系统已存在的数据库
• use databasesname; //选择需要使用的数据库
• drop database databasename; //删除选定的数据库
• exit //退出数据库的连接
• create database test01; //建立名为test的数据库
– mysql> show databases;
– +--------------------+
– | Database |
– +--------------------+
– | information_schema |
– | mysql |
– | test |
– | test01 |
– +--------------------+
– 4 rows in set (0.00 sec)
• 可以看到新建的test01数据库
• use test01; //连接到数据库test01
– mysql> use test01;
– Database changed
• mysql> create talbe test(num int,name varchar(50)); //在数据库中建立表
– mysql> create table test(num int,name varchar(50));
– Query OK, 0 rows affected (0.11 sec)
• mysql> insert into test values(1,’Hello World!’) ; //插入一个值到表中
– mysql> create table test(num int,name varchar(50));
– Query OK, 0 rows affected (0.11 sec)
• select * from test; //查看数据库中表的信息
– mysql> select * from test;
– +------+--------------+
– | num | name |
– +------+--------------+
– | 1 | Hello World! |
– +------+--------------+
– 1 row in set (0.00 sec)
附件:http://down.51cto.com/data/2362373
打入如下命令:
[root@mysql ~]# yum -y install mysql-server //自动从网上搜索资源并自动下载安装
[root@mysql ~]# chkconfig mysqld on //设置开机启动MySql服务
检查是否为开机启动
打入命令:[root@mysql ~]# chkconfig –list
看到:mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 即表示已设置为开机启动,2、3、4、5为on
启动MySql服务
/etc/rc.d/init.d/mysqld start //从文件启动MySql服务
service mysqld start //以服务名方式启动
MySql初始化环境设置(一)
设置MySQL的root用户设置密码,因为MySQL被安装时,它的root用户时没有设置密码的。
– [root@mysql ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
2. 如上,默认是不需要密码就可以进入数据库操作,下面查看MySQL数据库用户信息
MySql初始化环境设置(二)
打入命令:select user,host,password from mysql.user; //可以看到密码都为空
– +------+-----------+----------+
– | user | host | password |
– +------+-----------+----------+
– | root | localhost | |
– | root | mysql | |
– | root | 127.0.0.1 | |
– | | localhost | |
– | | mysql | |
– +------+-----------+----------+
– 5 rows in set (0.00 sec)
– set password for root@localhost=password(‘123456789’); //设置root用户密码为123456789
MySql初始化环境设置(三)
• 打入命令:select user,host,password from mysql.user; //查看刚设置的密码,可以看到密码已经经过加密处理
– +------+-----------+-------------------------------------------+
– | user | host | password |
– +------+-----------+-------------------------------------------+
– | root | localhost | *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D |
– | root | mysql | |
– | root | 127.0.0.1 | |
– | | localhost | |
– | | mysql | |
– +------+-----------+-------------------------------------------+
– 5 rows in set (0.00 sec)
• 打入exit命令退出数据库连接,测试root密码是否生效
MySql初始化环境设置(四)
• 打入命令:mysql –u root
– ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u root' at line 1
– 弹出图上提示说明刚设置的密码已生效
• 下面通过密码登陆,打入命令:mysql –u root –p //在Enter password后输入刚才设置的密码,看到下面即表示登陆成功
– [root@mysql ~]# mysql -u root -p
– Enter password:
– Welcome to the MySQL monitor. Commands end with ; or \g.
– Your MySQL connection id is 3
– Server version: 5.1.61 Source distribution
– Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
– Oracle is a registered trademark of Oracle Corporation and/or its
– affiliates. Other names may be trademarks of their respective
– owners.
– Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
– mysql>
增删改查语句
• Show databases; //查看系统已存在的数据库
• use databasesname; //选择需要使用的数据库
• drop database databasename; //删除选定的数据库
• exit //退出数据库的连接
• create database test01; //建立名为test的数据库
– mysql> show databases;
– +--------------------+
– | Database |
– +--------------------+
– | information_schema |
– | mysql |
– | test |
– | test01 |
– +--------------------+
– 4 rows in set (0.00 sec)
• 可以看到新建的test01数据库
• use test01; //连接到数据库test01
– mysql> use test01;
– Database changed
• mysql> create talbe test(num int,name varchar(50)); //在数据库中建立表
– mysql> create table test(num int,name varchar(50));
– Query OK, 0 rows affected (0.11 sec)
• mysql> insert into test values(1,’Hello World!’) ; //插入一个值到表中
– mysql> create table test(num int,name varchar(50));
– Query OK, 0 rows affected (0.11 sec)
• select * from test; //查看数据库中表的信息
– mysql> select * from test;
– +------+--------------+
– | num | name |
– +------+--------------+
– | 1 | Hello World! |
– +------+--------------+
– 1 row in set (0.00 sec)
附件:http://down.51cto.com/data/2362373
相关文章推荐
- centos 7 yum install mysql 安装mariadb 后 mysql 无法启动的解决方法
- CentOS 7.1使用yum安装MySql5.6.24
- CentOS 7.0下使用yum安装MySQL
- centos下yum搭建安装linux+apache+mysql+php环境的方法
- centos7下yum快速安装mariadb(mysql)
- CentOS 6.* yum安装配置lnmp服务器(Nginx+PHP+MySQL)
- centos6.8 yum安装mysql 5.6 (完整)
- CentOS 6.5 yum安装mysql5.6或其他版本【默认yum只能安装mysql 5.1】 by jason
- CentOS 6.5 yum安装配置lnmp服务器(Nginx+PHP+MySQL)
- centos下yum安装mysql5.6.41
- CentOS 6.5 yum安装配置lnmp服务器(Nginx+PHP+MySQL)
- CentOS 下使用yum 命令安装MySQL
- CentOS_6.5_64_yum安装mysql
- centos7下yum安装mysql
- Centos利用yum命令安装配置MySQL+Apache+PHP
- CentOS 6.5 中 Yum 方法安装 MySQL 5.7 完整步骤
- CentOS环境下yum安装LAMP(Linux+Apache+Mysql+php)
- centos7使用yum安装mariaDB(开源MySQL)无法启动的解决办法
- Centos6.5使用yum安装mysql
- 【Linux】CentOS7下yum安装MySQL