Copyright: https: //shirukai.github.io/ | https://blog.csdn.net/shirukai/article/details/85212633
Under CentOS7 yum simple configuration and installation MariaDB
Before starting, be sure you have yum installed and configured the relevant source.
First, the installation command:
yum -y install mariadb mariadb-server
Second, start MariaDB
systemctl start mariadb
Third, set the boot
systemctl enable mariadb
Fourth, the relevant configuration
mysql_secure_installation
1. Set password
Enter current password for root (enter for none): #直接回车就行
Set root password? [Y/n] y # 设置密码
New password:
Re-enter new password:
Remove anonymous users? [Y/n] # 是否删除匿名用户,删除就行
Disallow root login remotely? [Y/n] n # 是否禁止root远程登录,N
Remove test database and access to it? [Y/n] # 是否删除测试表,Y
Reload privilege tables now? [Y/n] # 是否重新加载权限表,Y
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
2. Log
mysql -uroot -proot
3. Configure MariaDB character set
a. Check the database character set
show variables like "%character%";show variables like "%collation%";
Is shown below
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
b. Modify the file /etc/my.cnf file
vi /etc/my.cnf
Added at [mysqld] tab
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
c. Modify the file /etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
Add [client] in
default-character-set=utf8
d. Modify file /etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
Add [MySQL] in
default-character-set=utf8
e. Restart MariaDB
systemctl restart mariadb
f. view the modified character set
Access to the database
mysql -uroot -proot
show variables like "%character%";show variables like "%collation%";
MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| 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.00 sec)
4. Add the user, set permissions
a. Create a user command
MariaDB [(none)]> create user inspur@localhost identified by 'inspur';
b. Authorization
grant all privileges on *.* to inspur@'localhost' identified by 'inspur';
b. awarded outside the network logon rights
grant all privileges on *.* to root@'%' identified by 'inspur';
Reference article:
CentOS 7.0 using yum MariaDB installation and simple configuration of MariaDB