MySQL数据库基本语句(3)

另一台客户机使用xiaoli访问
前提是CentOS 7客户端需安装MariaDB工具集,否则没有办法使用mysql工具。

[root@localhost ~]# rpm -ivh /mnt/Packages/mariadb-5.5.52-1.el7.x86_64.rpm [root@localhost ~]# mysql -u xiaoli -p -h 192.168.1.1 Enter password: MySQL [(none)]> //这样的标志表示客户端登录成功

撤销用户权限

mysql> revoke all on mysql.* from 'xiaoli'@'%'; //撤销xiaoli对mysql数据库的所有权限 Query OK, 0 rows affected (0.00 sec) mysql> show grants for 'xiaoli'@'%'; //再次查看权限列表,确认用户已无权限 +-------------------------------------------------------------------------------------------------------+ | Grants for xiaoli@% | +-------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'xiaoli'@'%' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' | +-------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> exit //退出MySQL数据库系统 Bye

设置数据库管理员密码
第一种方法:

mysql> update mysql.user set password=PASSWORD('123456') -> where user='root'; Query OK, 4 rows affected (0.00 sec) mysql> flush privileges; //刷新用户授权信息 Query OK, 0 rows affected (0.00 sec) [root@mysql /]# mysql -u root -p //登录输入设置的密码 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.6.36 Source distribution Copyright (c) 2000, 2017, 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@mysql /]# mysqladmin -u root password '123456' //输入警告信息可以忽略!

登录MySQL服务器就不用输入密码了。

[root@mysql /]# mysqladmin -u root -p'654321' password //使用mysqladmin工具更改密码;、 //-p后面跟旧密码,password后面是新密码 New password: //新密码可以为空,输入新密码确认 Confirm new password: [root@mysql /]# mysql -u root //不输入密码 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.6.36 Source distribution Copyright (c) 2000, 2017, 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@mysql /]# systemctl stop mysqld //先停止mysql服务 [root@mysql /]# mysqld_safe --skip-grant-tables & [1] 42462 //使用原始脚本启动服务,带参数 [root@mysql /]# 190722 10:06:37 mysqld_safe Logging to '/usr/local/mysql/data/mysql.err'. 190722 10:06:37 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data [root@mysql /]# mysql -u root //不输入密码登录 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.36 Source distribution Copyright (c) 2000, 2017, 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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1e3bcb581b9589f3a921ab806dcd6a77.html