centOS Linux下用yum安装mysql(二)
sword ('在这里填入root密码'); ← 设置root密码
譬如,在我的
系统中,我是如下设置:
mysql> set password for root@localhost=password ('wangyun');
Query OK, 0 rows affected (0.01 sec)
mysql> set password for root@192.168.0.1=password ('wangyun');
Query OK, 0 rows affected (0.01 sec)
mysql> set password for root@127.0.0.1=password ('wangyun');
Query OK, 0 rows affected (0.01 sec)
mysql> select user,host,password from mysql.user; ← 查看用户信息
+------+-------------+------------------+
| user | host | password |
+------+-------------+------------------+
| root | localhost | 5f2dfe4b07af795b |
| root | 192.168.0.1 | 5f2dfe4b07af795b |
| root | 127.0.0.1 | 5f2dfe4b07af795b |
| | localhost | |
| | 192.168.0.1 | |
+------+-------------+------------------+
5 rows in set (0.01 sec)
mysql> exit ← 退出MySQL服务器
Bye
[2] 测试设置的root密码是否生效
[root@192 local]# mysql -u root ← 通过空密码用root登录
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
← 出现此错误信息说明密码设置成功
[root@192 local]# mysql -u root-p ← 通过密码用root登录
Enter password: ← 在这里输入密码
Welcome to the MySQL monitor. Commands end with ; or \g. ← 确认用密码能够成功登录
Your MySQL connection id is 5
Server version: 5.0.95 Source distribution
... ...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[root@192 local]#mysql -u root -h 127.0.0.1 -p ← 通过密码用root登录
Enter password: ← 在这里输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.← 确认用密码能够成功登录
Your MySQL connection id is 13
Server version: 5.0.95 Source distribution
......
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit ← 退出MySQL服务器
Bye
[3] 删除匿名用户
在MySQL刚刚被安装后,存在用户名、密码为空的用户。这使得数据库服务器有无需密码被登录的可能性。为消除隐患,将匿名用户删除。
[root@192 local]# mysql -u root -p; ← 通过密码用root登录
Enter password: ← 在这里输入密码
mysql> select user,host from mysql.user;
+------+-------------+
| user | host |
+------+-------------+
| root | 127.0.0.1 |
| | 192.168.0.1 |
| root | 192.168.0.1 |
| | localhost |
| root | localhost |
+------+-------------+
5 rows in set (0.03 sec)
mysql> delete from mysql.user where user=''; ← 删除匿名用户
Query OK, 2 rows affected (0.04 sec)
mysql> select user,host from mysql.user; ← 查看用户信息
+------+-------------+
| user | host |
+------+-------------+
| root | 127.0.0.1 |
| root | 192.168.0.1 |
| root | localhost |
+------+-------------+
3 rows in set (0.00 sec)
mysql> flush privileges; ← 刷新,使以上操作生效
mysql> exit; ←退出MySQL服务器
Bye
第三篇:测试
经过第一篇和第二篇这二部分的设置,MySQL就可以正常试用。
好了,第三篇的内容都不是必须的了!
我们来测试MySQL,让我们学习或复习常用的SQL语句。
[root@192 local]#mysql -u centospub-p; ← 通过密码用root登录
Enter password: ← 在这里输入密码
mysql> grant all privileges on test.* to centospub@localhost identified by '在这里定义密码';
← 建立对test数据库有完全操作,权限的名为centospub的用户
譬如,在我的系统中,设置如下:
mysql>grant all privileges on test.* to centospub@localhost identified by'wangyun';
Query OK, 0 row