二、配置MySQL数据库
2.1 访问测试登陆情况
mysql -uroot -p-S /data/3306/mysql.sock
Enter password:
Welcome to theMySQL monitor. Commands end with ; or \g.
Your MySQLconnection id is 1
Server version:5.1.51-log Source distribution
Type 'help;' or'\h' for help. Type '\c' to clear the buffer.
mysql>select version();
+------------+
| version() |
+------------+
| 5.1.51-log |
+------------+
1 row in set(0.02 sec)
mysql>system mysql -uroot -p -S /data/3307/mysql.sock #-->system的用法
Enter password:
Welcome to theMySQL monitor. Commands end with ; or \g.
Your MySQLconnection id is 1
Server version:5.1.51-log Source distribution
Copyright (c)2000, 2010, Oracle and/or its affiliates. All rights reserved.
This softwarecomes with ABSOLUTELY NO WARRANTY. This is free software,
and you arewelcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
mysql> showdatabases;
+--------------------+
| Database |
+--------------------+
|information_schema |
| mysql |
| test |
+--------------------+
3 rows in set(0.01 sec)
mysql> quit
Bye
提示:安装完mysql初始登陆管理员root用户无密码。
更改root密码
mysqladmin -uroot password 'bdkyr14511' -S/data/3306/mysql.sock
mysqladmin -uroot password 'bdkyr14511' -S/data/3307/mysql.sock
#测试改密码后的登陆情况
mysql -uroot -p'bdkyr14511' -S /data/3306/mysql.sock
Welcome to theMySQL monitor. Commands end with ; or \g.
Your MySQLconnection id is 3
Server version:5.1.51-log Source distribution
Type 'help;' or'\h' for help. Type '\c' to clear the buffer.
mysql> system mysql -uroot -p'bdkyr14511' -S /data/3307/mysql.sock
ERROR 1045(28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql>system mysql -uroot -p'bdkyr14511' -S /data/3307/mysql.sock
Welcome to theMySQL monitor. Commands end with ; or \g.
Your MySQLconnection id is 4
Server version:5.1.51-log Source distribution
Copyright (c)2000, 2010, Oracle and/or its affiliates. All rights reserved.
This softwarecomes with ABSOLUTELY NO WARRANTY. This is free software,
and you arewelcome to modify and redistribute it under the GPL v2 license
Type 'help;' or'\h' for help. Type '\c' to clear the current input statement.
提示:一般产品环境,禁止将密码写在命令行中,非常危险。
2.2清理系统默认的多余mysql用户
mysql -uroot -p'bdkyr14511' -S /data/3306/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQLconnection id is 4
Server version:5.1.51-log Source distribution
Type 'help;' or'\h' for help. Type '\c' to clear the buffer.
mysql>select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root |127.0.0.1 |
| | A |
| root | A |
| | localhost |
| root |localhost |
+------+-----------+
5 rows in set(0.00 sec)
mysql> dropuser ''@'localhost';
Query OK, 0rows affected (0.04 sec)
mysql> dropuser ''@'A';
Query OK, 0rows affected (0.01 sec)
mysql> dropuser 'root'@'A';
Query OK, 0rows affected (0.00 sec)
mysql>select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root |127.0.0.1 |
| root |localhost |
+------+-----------+
2 rows in set(0.00 sec)
用同样的方法处理3307的用户。
处理后结果:
mysql>select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root |127.0.0.1 |
| root |localhost |
+------+-----------+
2 rows in set(0.00 sec)
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/108223.htm
