創(chuàng)建新用戶
? mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE USER username IDENTIFIED BY 'password'
Query OK, 0 rows affected (0.01 sec)
給用戶授權(quán)
mysql> GRANT select,update,otherprivileges ON databasename.tablename TO username
示例:
mysql> GRANT all ON database_test.* TO user_test #給user_test用戶所有在數(shù)據(jù)庫database_test上的權(quán)限雷厂。
Query OK, 0 rows affected (0.00 sec)
成功,然后就可以登陸了专普。
其他問題
有時(shí)候新用戶登錄會出現(xiàn)如下錯(cuò)誤
mysql>ERROR 1045 (28000): Access denied for user 'test@localhost'(using password: YES)
這是因?yàn)閿?shù)據(jù)庫中存在空用戶蒂教,登錄時(shí)User字段為空的匿名用戶將占先肾扰,解決方案:刪掉所有用戶名為空的記錄畴嘶,或者把空用戶名的用戶改為其他名字.
mysql> delete from user where User is NULL
或者
mysql> update user set user='mytest' where User is NULL
如果mysql.user表里面沒有可以訪問的用戶,也會出現(xiàn) ERROR 1045 (28000): Access denied for user 'test@localhost'(using password: YES)
的錯(cuò)誤集晚,此時(shí)可以使用以下解決方案:
? service mysql stop
Shutting down MySQL...[ OK ]
? mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
? mysql -uroot
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * from user;
Empty set (0.01 sec) #發(fā)現(xiàn)沒有用戶
mysql> INSERT INTO user(host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'username', PASSWORD(‘yourpassword'), 'Y', 'Y','Y');
Query OK, 1 row affected, 3 warnings (0.00 sec)
成功窗悯。