远程登入mysql

mysql 开启远程连接

1. 修改/etc/mysql/mysql.conf.d/mysqld.cnf 文件

找到bind-address = 127.0.0.1这一行

改为bind-address = 0.0.0.0即可

2.在连接服务器后,操作mysql系统数据库

root@default:/home# mysql
mysql> use mysql

mysql> select User,authentication_string,Host from user;
+------------------+-------------------------------------------+-----------+
| User             | authentication_string                     | Host      |
+------------------+-------------------------------------------+-----------+
| root             |                                           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| debian-sys-maint | *41F11B84A5CC2C8B953416E91A263DCCE0FB3DB7 | localhost |
+------------------+-------------------------------------------+-----------+
4 rows in set (0.00 sec)

3. 创建可以访问的用户名即密码

GRANT ALL PRIVILEGES ON . TO '账号'@'%' IDENTIFIED BY '密码';

%代表所有主机,也可以具体到你的主机ip地址

用户名处,填写自己的用户名, 密码处,填写自己访问的密码

mysql> grant all privileges on *.* to root@'%' identified by '123456';
# 重载授权表
mysql> flush privileges;

4. 重启mysql

service mysql restart

Mariadb

与mysql 唯一区别:修改的配置文件不同

/etc/mysql/mariadb.conf.d/50-server.cnfbind-address = 127.0.0.1# 注释掉

# mysql   Mariadb  

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×