阿里云安装配置mysql(Debian 9 mysql被替换为mariaDB)

实验环境:debian 9

sudo apt install mysql-server
sudo apt install mysql-client

发现并没有像在ubuntu 16.04上那样在安装期间要求输入root用户密码……

原因是Debian 9 中使用 MariaDB 彻底代替了 MySQL

因为 Debain 9 源内的 MariaDB 10.0 使用了 UNIX 套接字认证,所以在全新安装 MariaDB 的过程中,不再有 MySQL root 密码的配置窗口。

关于本部分的详细内容参阅:
https://mariadb.com/kb/en/library/moving-from-mysql-to-mariadb-in-debian-9/#secure-passwordless-root-accounts-only-on-new-installs

第一次用root登录时使用空密码即可登录

mysql -u root -p

阿里云安装配置mysql(Debian 9 mysql被替换为mariaDB)_第1张图片
image.png

当然我们必须马上设置root密码:

use mysql

UPDATE user SET Password = password('新密码') WHERE User = 'root';

flush privileges;

使用原生 MySQL 认证

因为默认使用了 UNIX SOCKET 认证,有些 phpMyAdmin 在登入时会发生 “Access Denied” 错误。我们可以更改 UNIX SOCKET 认证为原生 MySQL 认证。

接着上面执行:

update mysql.user set plugin = 'mysql_native_password' where User='root';

flush privileges;
exit

设置远程连接

mysql默认下只能本地连接数据库,要远程连接需要修改配置文件:

vi /etc/mysql/mariadb.conf.d/50-server.cnf

修改bind-address = 0.0.0.0或者直接注释,保存退出;
接下来授予用户具有远程访问的权限:

grant all privileges on . to 'root'@'%' identified by 'password';

flush privileges;

或直接创建一个新的用户:

create user 'django'@'%' identified by 'password';

'%'为通配符,指定该用户可以从任意主机远程登录;

使用命令行远程连接

mysql -h ip -P port -u username -p

debian下的可视化管理工具推荐Workbench

最后重启数据库服务

service mariadb restart

你可能感兴趣的:(阿里云安装配置mysql(Debian 9 mysql被替换为mariaDB))