MySQL/MariaDB Setting¶
User¶
USE mysql;
- Check users
MariaDB [mysql]> select user,host,plugin from user;
+--------------+-----------+-----------------------+
| user | host | plugin |
+--------------+-----------+-----------------------+
| root | localhost | unix_socket |
| .... | localhost | |
| xxx | localhost | |
| ???? | localhost | mysql_native_password |
| ???? | % | mysql_native_password |
+--------------+-----------+-----------------------+
-
Create a user
1 2
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password; # 本機 CREATE USER 'username'@'%' IDENTIFIED BY 'password; # 遠端
-
Set plugin
mysql_native_password
unix_socket
/auth_socket
1 |
|
- Grant privileges Ref
1 2
GRANT ALL PRIVILEGES ON *.* TO 'username'@'host'; FLUSH PRIVILEGES;
1 |
|
- Set password for a user
1 2 |
|
mysqladmin -u user -p'old' password 'new'
Allow remote access¶
-
Comment
bind-address
- mysql
- <= 5.5
/etc/mysql/my.cnf
- >= 5.6
/etc/mysql/mysql.conf.d/mysqld.cnf
- <= 5.5
- mariadb:
/etc/mysql/mariadb.conf.d/50-server.cnf
- mysql
-
Restart mysql service
1 |
|
Reference¶
解决 MySQL 的 ERROR 1698 (28000): Access denied for user 'root'@'localhost'
https://blog.csdn.net/jlu16/article/details/82809937
[MySQL] 資料庫密碼修改處理 – MySQL Password Change
https://code.yidas.com/mysql-password-change/
MySQL 允許外部連入
https://contemplator.github.io/blog/2018/06/06/Mysql-%E5%85%81%E8%A8%B1%E5%A4%96%E9%83%A8%E9%80%A3%E5%85%A5/
http://itman.in/en/mysql-add-user-for-remote-access/
https://www.digitalocean.com/community/tutorials/how-to-allow-remote-access-to-mysql