第一步:代码:apt install mariadb-client -y
第二部:代码:apt install mariadb-server -y
第三步:设置开机启动服务:systemctl enable mysql
停止mysql服务 : systemctl disable mysql
然后启动mysql : systemctl start mysql
第四步:sudo mysql_secure_installation 配置数据库的密码
In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none) # ,输入系统的密码,按回车健
后面全部选择Y,
You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] y New password: #这里是创建数据库 root 登录密码 Re-enter new password: #这里是再次输入 root 登录密码
后面也全部是Y
第五步:mysql -u root -p 输入密码
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 67 Server version: 10.5.12-MariaDB-1 Debian 11 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
后面就开始创建用户。
第六步、 创建用户:CREATE USER '用户名'@'%' IDENTIFIED BY '密码';
返回:Query OK, 0 rows affected (0.008 sec) 表示成功
第七步、 授权用户远程登录:grant all privileges on *.* to '用户'@'%' with grant option;
返回:Query OK, 0 rows affected (0.008 sec) 表示成功
第八步、刷新: flush privileges;
返回:Query OK, 0 rows affected (0.008 sec) 表示成功
第九步、修改一个配置文件 : vim /etc/mysql/mariadb.conf.d/50-server.cnf
注释掉:bind-address = 127.0.0.1
最后重启 mariadb 服务: systemctl restart mysql 完