$ mysql -u rootERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)$ mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 75Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.mysql>
建立数据库独立用户
因为root用户拥有数据库的所有操作权限,所以不能轻易地提供给别人使用。在一个MySQL实例中可以创建多个数据库,这些数据库可能归属于不同项目,每个数据库的操作角色也不一样。对此可以针对不同那个数据库指定用户进行访问。
首先使用root角色创建一个数据库mysql> create database db_web_monitor然后将这个数据库授予一个叫xavier的用户使用mysql> GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@localhost IDENTIFIED BY "xavier";
这样就可以使用xavier用户,密码为xavier在本机登录MySQL操作db_web_monitor数据库了。
$ mysql -u xavierERROR 1045 (28000): Access denied for user 'xavier'@'localhost' (using password: NO)$ mysql -u xavier -pEnter password: Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 77Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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>
开放远程登录权限
1. 首先修改MySQL的配置文件,允许监听远程登录。
$ 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值修改为本机IP即可。注意注释说明,如果是较老版本的MySQL,此处就应该是skip-networking,直接将其注释即可。
2. 授予用户远程登录权限。
mysql>GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@"%" IDENTIFIED BY "xavier";










