Reference article:
https://blog.csdn.net/dongdong9223/article/details/86687735
Ready to work
1. Set the firewall port
firewall-cmd --zone=public --add-port=3306/tcp --permanent
Reload:
firewall-cmd --reload
View all open ports:
firewall-cmd --zone=public --list-ports
2. See if CentOS comes with MariaDB
rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
3. View the MariaDB installation package configuration file
rpm -qc mariadb-libs-5.5.56-2.el7.x86_64
/etc/my.cnf
/etc/my.cnf.d/mysql-clients.cnf
In addition: you can use rpm -qi to view the installation package information, and use rpm -ql to view the location of all files in the installation package.
4. Uninstall the installed MariaDB
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
2. Download MariaDB
Baidu SkyDrive Download
Link: https://pan.baidu.com/s/1I1ONRLOM7mEv5sZw8_4MSQ
Extraction code: hyop
Three, install MariaDB
Go to the cd /home/software/mariadb/ directory
cd /home/software/mariadb/
1. Unzip the tar.gz file
tar -zxvf mariadb-10.2.21-linux-x86_64.tar.gz
mv mariadb-10.2.21-linux-x86_64 /usr/local
2. Move the decompressed folder to the /usr/local folder
cd /usr/local
mv mariadb-10.2.21-linux-x86_64 mysql
3. Create mysql user group and users
groupadd mysql
useradd -g mysql mysql
4. Authorize the mysql folder:
cd /usr/local/
chown -R mysql:mysql /usr/local/mysql
5. Set environment variables
Modify the configuration file:
vi /etc/profile
add content:
# set for mariadb export MARIADB=/usr/local/mysql export PATH=$MARIADB/bin:$PATH
#Effective configuration file
source /etc/profile
6. Copy the my.cnf file (optional)
Go to the /usr/local directory
cd /usr/local/mysql/
cp support-files/my-huge.cnf my.cnf
That is, put it in the mysql directory.
In fact, there are several files in the support-files folder:
my-huge.cnf
my-large.cnf
my-medium.cnf
my-small.cnf
These files are for different database sizes, you can check the comments at the beginning of the file content to find out.
7. Copy mysql.server as mysqld
File:
/usr/local/mysql/support-files/mysql.server
Copy as:
/etc/init.d/mysqld
The command is as follows:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
8. Initialization
Install libaio
Follow libaio before initialization, the command is as follows:
yum install libaio
Otherwise, an error will be reported:
error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
7.2 Initialize MariaDB
Use the command:
./scripts/mysql_install_db --user=mysql
or:
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --defaults-file=/usr/local/mysql/my.cnf
Pay special attention here! The command is:
./scripts/mysql_install_db --user=mysql
Instead of:
scripts/mysql_install_db --user=mysql
The dot and slash symbol in front of the folder scripts cannot be omitted!
9. Check status
service mysqld status
[root@shizhi001 mysql]#
MariaDB running (818) [ OK ]
10. Start MariaDB
service mysqld start
Starting MariaDB.190129 15:05:00 mysqld_safe Logging to '/usr/local/mysql/data/shizhi001.err'.
190129 15:05:00 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data [OK]
11. Set the database root user password
Go to the /usr/local/mysql directory
cd /usr/local/mysql
Set root user password
./bin/mysqladmin -u root password '123456'
View hostname
hostname
mariadb
Set the root user password to connect to this host
./bin/mysqladmin -u root -h mariadb password '123456'
5. Close the database
./bin/mysqladmin -uroot -p shutdown
Enter password: [1]+ Done ./bin/mysqld_safe --user=mysql
Set up remote access
Four, database connection, query
1. Connect and log in
./bin/mysql -uroot -p
Enter password:
#Enter password 123456
MariaDB [(none)]> show databases;
MariaDB [(none)]> use mysql;
MariaDB [mysql]> desc user;
MariaDB [mysql]> select host,user,password from user;
#Note: root is the user who logs in to the database, 123456 is the password to log in to the database, * means any host from any source
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
#Refresh to take effect
mysql> FLUSH PRIVILEGES;
MariaDB adds a boot-up service:
chkconfig --add mysqld
View the boot-up service:
chkconfig --list
Restart the server and verify whether the configuration is successful at startup