MariaDB15 remote connection problem
surroundings
mariadb Ver 15.1 Distrib 10.1.38-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Ubuntu 18.04.2
problem
mysql -h 192.168.0.5 -u root -p
The error is as follows:
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.0.4’ (111 “Connection refused”)
Solution
Refer to the official explanation (true fragrance)
https://mariadb.com/kb/en/library/configuring-mariadb-for-remote-client-access/
- Comment out the bind-address under /etc/mysql/mariadb.conf.d/50-server.cnf, as shown below:
# Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. #bind-address = 127.0.0.1
- Permission to write to the database
Enter the mysql command line
GRANT ALL PRIVILEGES ON *.* TO 'USER_NAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Write USER_NAME, PASSWORD according to your needs.
Be sure to let USER_NAME have all permissions, just a data table is not enough, and then refresh the permissions table.
FLUSH PRIVILEGES;
- Restart the service
Be sure to restart mysql\mysql\mariadb
service mysql restart
service mariadb restart
service mysqld restart
- Have fun
Python script to test whether mariadb is connected
import pymysql
conn = pymysql.Connect(host='192.168.0.2',user='keystone',passwd='keystone1001',db='keystone')
cur = conn.cursor()
cur.execute("select version()")
for i in cur:
print(i)
cur.close()