MySql 数据库管理

//开启和关闭

rize@rize-laptop ~> sudo service mysql stop

 * Stopping MySQL database server mysqld                                                         [ OK ]
rize@rize-laptop ~> sudo service mysql start
 * Starting MySQL database server mysqld                                                         [ OK ]

 * Checking for corrupt, not cleanly closed and upgrade needing tables.

 

// 添加用户,可以在任何主机上登录
mysql> grant select,insert,update,delete on *.* to 'rize'@'%'identified by 'pass_word';

Query OK, 0 rows affected (0.00 sec)

 

 //添加用户,只能在本机上登录

 mysql> grant select,insert,update,delete on jinrize.* to 'test'@'localhost' identified by 'pass_word';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

rize@rize-laptop ~> mysql -u test -p
Enter password:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| jinrize            |
+--------------------+

//建立一个本地完全的超级用户admin

 mysql> grant all privileges on *.* to admin@localhost identified by 'pass_word' with grant option;
Query OK, 0 rows affected (0.00 sec)

查看系统用户信息: 在mysql数据库中查看,select user from user;

 

//删除用户

mysql> revoke all on *.* from rize@'%';
Query OK, 0 rows affected (0.00 sec)

//删除了权限,但是用户还是在用户表里,能登录mysql,但是不能操作任何数据库。

//删除用户信息

 mysql> delete from mysql.user where user='rize';
Query OK, 1 row affected (0.00 sec)
//刷新内存授权表
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

//删除匿名用户

 mysql> delete from user where host='localhost' and user='';
Query OK, 0 rows affected (0.00 sec)

 mysql> flush privileges;

 

//修改密码

rize@rize-laptop ~> mysqladmin -uroot -pold_pwd password new_pwd;

//或者直接进入user表,进行修改password.

//清除密码

rize@rize-laptop ~> mysqladmin -uroot -pold_pwd password ''

 记得都要 flush privileges;

 

你可能感兴趣的:(mysql)