$ mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
mysql> use mysql
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 75
Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)
Copyright (c) 2000, 2013, 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>
首先使用root角色創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)
mysql> create database db_web_monitor
然后將這個(gè)數(shù)據(jù)庫(kù)授予一個(gè)叫xavier的用戶(hù)使用
mysql> GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@localhost IDENTIFIED BY "xavier";
$ mysql -u xavier
ERROR 1045 (28000): Access denied for user 'xavier'@'localhost' (using password: NO)
$ mysql -u xavier -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 77
Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)
Copyright (c) 2000, 2013, 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;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_web_monitor |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql>
開(kāi)放遠(yuǎn)程登錄權(quán)限
1. 首先修改MySQL的配置文件,允許監(jiān)聽(tīng)遠(yuǎn)程登錄。
$ sudo vi /etc/mysql/my.cnf
找到bind-address所在行
45 # Instead of skip-networking the default is now to listen only on
46 # localhost which is more compatible and is not less secure.
47 bind-address = 127.0.0.1
將 bind-address值修改為本機(jī)IP即可。
注意注釋說(shuō)明,如果是較老版本的MySQL,此處就應(yīng)該是skip-networking,直接將其注釋即可。
2. 授予用戶(hù)遠(yuǎn)程登錄權(quán)限。
mysql>GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@"%" IDENTIFIED BY "xavier";