Armbian安装Mysql(MariaDB)数据库
debian9默认情况下,Mysql数据库已经替换为MariaDB数据库,配置方式已经同原Mysql不同。 通过apt安装mysql-server后,需要进行一些列的配置,才能成功登录
一、安全配置
运行脚本mysql_secure_installation,无需密码,进行部分按权设置
- 配置root密码
- 删除匿名帐号
- 启用root的远程登录
- 删除test数据库
- 立即刷新数据库权限
bytetoy@aml:~$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
二、权限配置
按权配置后,可以使用mysql直接登录,然后可以新建帐号和配置权限
- 新建帐号:
GRANT ALL PRIVILEGES on *.* TO 'admin'@'%' IDENTIFIED BY '9527' WITH GRANT OPTION;
- 设置帐号密码:
SET PASSWORD FOR admin=PASSWORD('9527');
- 刷新权限:
FLUSH PRIVILEGES;
bytetoy@aml:~$ sudo mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.48-MariaDB-0+deb9u2 Debian 9.13
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)]>
MariaDB [(none)]> GRANT ALL PRIVILEGES on *.* TO 'admin'@'%' IDENTIFIED BY '9527' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SET PASSWORD FOR admin=PASSWORD('9527');
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
三、测试新帐号
查看数据库版本
sudo mysqladmin -u admin -p version
bytetoy@aml:~$ sudo mysqladmin -u admin -p version
Enter password:
mysqladmin Ver 9.1 Distrib 10.1.48-MariaDB, for debian-linux-gnu on aarch64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Server version 10.1.48-MariaDB-0+deb9u2
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 10 min 21 sec
Threads: 2 Questions: 13 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 11 Queries per second avg: 0.020
使用新帐号登录,测试是否设置成功
bytetoy@aml:~$ mysql -h localhost -u admin -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.1.48-MariaDB-0+deb9u2 Debian 9.13
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)]>
四、配置帐号远程登录
- 修改配置文件:
sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
- 修改绑定的IP地址,然后重启mysql服务
bind-address=0.0.0.0 #原为127.0.0.1 systemctl restart mysqld