安装并设置root密码
## apt 安装
sudo apt install mariadb-server
## 开机启动,启动服务
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
## 允许数据库基本初始化设置,初始密码为空
sudo mysql_secure_installation
## 本机登陆数据库
sudo mysql -u root -p
## 设置 root 密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
## 查看是否生效
SELECT host,user,password from user;
## 修改配置
将 /etc/mysql/mariadb.conf.d/50-server.cnf 中 bind-address=127.0.0.1 加 # 注释掉
## 重启服务
sudo systemctl restart mariadb.service
遇到的问题
mysql (mariadb) ERROR 1698 (28000): Access denied for user 'root'@'localhost'
sudo mysql -u root
use mysql;
update user set plugin='' where User='root';
flush privileges;
exit;