CentOS 7 installation of MariaDB 10 and related configuration, centosmariadb
Step 1: Add MariaDB yum Repository
Add the MariaDB yum configuration file MariaDB. repo in the/etc/YUM. repos. d/directory of the CentOS operating system.
Vi/etc/yum. repos. d/MariaDB. repo
Add the following content to save the file:
[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.2/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1
Step 2: Install MariaDB
Install MariaDB easily using the yum command.
Yum install MariaDB-server MariaDB-client-y
After MariaDB is installed, immediately start the database service daemon process.
Systemctl start mariadb
Set MariaDB to automatically start the service after the operating system restarts.
Systemctl enable mariadb
View the current status of the MariaDB service.
Systemctl status mariadb
Step 3: Configure MariaDB Security
Run the following command to perform security configuration and use Y/N to reply to the following questions: Set the root account password of MariaDB, delete anonymous users, disable root remote logon, and delete the test database, reload the permission table.
Mysql_secure_installation
I chose Y and press Enter.
After configuring the Security Configuration of the database, run the following command to check the version to verify that MariaDB has been installed successfully.
Mysql -- version
You can log on through the MariaDB command line and perform SQL query on the database.
Mysql-u root-p
Step 4: configure remote access permissions for MariaDB
In step 3, If you disable root remote logon and select Y, you cannot connect to the database on another computer using tools such as navicat. In this case, you need to assign permissions to the corresponding MariaDB account, allow this account to remotely connect to MariaDB. Run the following command to view the account information:
Select User, host from mysql. user;
The host entry in the root account is localhost, indicating that this account can only perform local login. We need to modify the permission and enter the command:
Grant all privileges on *. * TO 'root' @ '%' identified by 'Password' with grant option;
Modify permissions. % Indicates all IP addresses, and password indicates that the password will be used to log on to the root user. To connect only hosts in an IP segment, you can change it:
Grant all privileges on *. * TO 'root' @ '1970. 192.% 'identified by 'my-new-password' with grant option;
Don't forget:
Flush privileges;
Save the changes and check the user account information:
At this time, we found that the host item is %, which indicates that the configuration is successful. We can use this account for remote access.
Step 5: Open the firewall port in CentOS 7
After step 4, if the database cannot be remotely connected, port 3306 is blocked by the firewall. In this case, we need to disable the firewall or open the firewall port.
Disable Firewall:
Systemctl stop firewalld. service # stop firewall
Systemctl disable firewalld. service # disable firewall startup
Open the firewall port. Restart the firewall after it is enabled:
Firewall-cmd -- zone = public -- add-port = 3306/tcp -- permanent
Firewall-cmd -- reload
Step 6: Set the database letters to be case insensitive
Vi/etc/my. cnf. d/server. cnf
Add
lower_case_table_names=1
The default value is 0, which is case sensitive. Change to 1 and then OK. If you have already created a database, you must delete it before it takes effect.
Step 7: Set the default encoding of the MariaDB Database
MariaDB's default encoding is latin1, and Chinese characters are garbled. Therefore, you need to change the encoding to utf8.
1. log on and use the following command to view the character set currently in use. Several of them should not be in utf8 format.
Show variables like 'character % ';
2. Modified configuration file
Vi/etc/my. cnf. d/client. cnf
Add in the [client] Field
default-character-set=utf8
Vi/etc/my. cnf. d/server. cnf
Add in the [mysqld] Field
character-set-server=utf8
3. Restart the MariaDB configuration to take effect.
Systemctl restart mariadb