版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28652401/article/details/83478980
MySql数据库,允许远程登录,任何主机上都能登录MySQL数据库
1、登录mysql客户端
[root@node1 ~]# mysql -uroot -p000000
2、显示数据库
mysql>show databases;
3、使用mysql数据库
mysql>use mysql;
4、展示mysql数据库中的所有表
mysql>show tables;
5、展示user表的结构
mysql>desc user;
6、查询user表
mysql>select user,host,authentication_string from user;
尖叫提示:mysql5.6密码使用的是password字段
7、修改user表,把Host表内容修改为%
mysql>update user set host='%' where user='root' and host='localhost';
尖叫提示:代替方法
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '000000' WITH GRANT OPTION;
8、删除root用户的其他host
mysql> delete from user where user='root'and host!='%';
mysql> delete from user where user=''and host!='%';
9、刷新
mysql>flush privileges;
10、退出
mysql> quit;
11、设置开机启动
查看mysql开机启动的状态
[root@node1 ~]# chkconfig mysql --list
设置mysql开机启动
[root@node1 ~]# chkconfig mysql on
设置mysql开机不启动
[root@node1 ~]# chkconfig mysql off
尖叫提示:使用root用户设置或使用sudo命令
mysql5.7版本开机启动/禁用的命令是
systemctl enable mysqld
systemctl disable mysqld
systemctl daemon-reload
也可以把启动命令写入到rc.local文件中
echo 'service mysql start' >> /etc/rc.local