1、mariadb安装
[root@localhost ~]# yum -y install mariadb mariadb-server
#安装完成后启动mariadb并添加到自启动
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb
#mariadb设置:root密码等
[root@localhost ~]# mysql_secure_installation
1、设置密码,首次进入无密码,直接回车
Enter current password for root (enter for none): 回车
OK, successfully used password, moving on...
2、设置root密码
Set root password? [Y/n] y
New password: 输入root密码
Re-enter new password: 输入root密码
Password updated successfully!
Reloading privilege tables..
... Success!
3、是否删除匿名用户
Remove anonymous users? [Y/n] 回车
... Success!
4、是否禁止root远程登录
Disallow root login remotely? [Y/n]
... Success!
5、是否删除test数据库
Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
6、是否重新加载权限表
Reload privilege tables now? [Y/n]
... Success!
Cleaning up...
mariadb安装完成,使用mysql -uroot -p登录测试
2、mariadbz字符集配置
修改/etx/my.cnf,在[mysqld]下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
修改/etc/my.cnf.d/client.cnf,在[client]中添加
default-character-set=utf8
修改/etc/my.cnf.d/mysql-clients.cnf,在[mysql]中添加
default-character-set=utf8
重启mariadb
[root@localhost ~]# systemctl restart mariadb
进入mariadb查看字符集
MariaDB [(none)]> show variables like "%character%";show variables like "%collat ion%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.01 sec)
3、用户、权限设置
配置root允许远程访问
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected (0.03 sec)
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
创建用户命令
create user username@localhost identified by 'password';
直接创建用户并授权的命令
grant all privileges on *.* to test@'%' identified by 'test';
授予外网登陆权限
grant all privileges on *.* to username@'%' identified by 'password';
授予权限并且可以授权
grant all privileges on *.* to username@'192.168.100.200' identified by 'password' with grant option;