用root账号进入MySQL管理后台,它会提示你输入密码:
[iyunv@localhost ~]# mysql -u root –p
创建本地用户:
mysql> create user '用户名'@'localhost' identified by '密码';
创建新数据库:
mysql> create database 数据库名;
将指定数据库的所有权限授给指定用户:
mysql> grant all privileges on 数据库名.* to '用户名'@'localhost';
刷新系统权限表:
mysql> flush privileges;
进入mysql数据库(系统自带),并查询是否存在指定用户(如果有出现一堆东西,则表明存在):
mysql> use mysql;
mysql> select * from user where user = '用户名';
如果要删除本地用户,使用:
mysql> drop user '用户名'@'localhost';
如果要删除数据库,使用:
mysql> drop database 数据库名;
查看存在的数据库:
mysql> show databases;
退出MySQL管理后台:
mysql> exit
[iyunv@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create user 'rex'@'localhost' identified by 'rexhaha'
-> ;
##上面那句结尾忘记加;号了,所以到一下行才加上
Query OK, 0 rows affected (0.02 sec)
##执行成功的反馈
MariaDB [(none)]> create database rexhome;
##创建rexhome数据库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to 'rex' @ 'localhost';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''localhost'' at line 1
##报错提示
MariaDB [(none)]> grant all privileges on rexhome.* to 'rex' @ 'localhost' ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''localhost'' at line 1
##加数据库名测试了一下还是报错
MariaDB [(none)]> grant all privileges on rexhome.* to 'rex'@'localhost' ;
##原来是在‘user’@‘host’地方加了空格
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> grant all privileges on *.* to 'rex'@'localhost' ;
##授权给rex账号,所有数据及所有表的权限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
更新权限表
Query OK, 0 rows affected (0.00 sec)