1. Uninstall Mariadb delivered with the system

  rpm -qa|grep mariadb
Copy the code

2. If yes

 rpm -e --nodeps  mariadb-libs5.544.- 2.El7.centos.x86_64 (this is what is shown above)Copy the code

3. Delete the my. CNF file in the etc directory

  rm /etc/my.cnf
Copy the code

4. Check whether the mysql database exists

  rpm -qa | grep mysql
Copy the code

5. Check whether the mysql group and user exist

  cat /etc/group | grep mysql 
  cat /etc/passwd | grep mysql
Copy the code

6. Create a mysql user group

  groupadd mysql
Copy the code

7. Create a mysql user and add it to the mysql user group

  useradd -g mysql mysql
Copy the code

8. Set password to root (your own choice)

  passwd mysql
Copy the code

9. I’m running out of space in /usr/local, so I’m installing /var

 tar -zxvf mysql5.718.-linux-glibc2. 5-x86_64.tar.gz 
 mv mysql5.718.-linux-glibc2. 5-x86_64/ mysql
Copy the code

10. Change the owning group and user to the /usr/local directory

cd /usr/local
 chown -R mysql mysql/
 chgrp -R mysql mysql/
 cd mysql/

 mkdir data

 chown -R mysql:mysql data
Copy the code

11. Create the configuration file my. CNF in etc

Mysql client default character setdefault-character-set=utf8 [mysqld] skip-name-resolve #3306Port the port =3306Datadir =/usr/local/mysql/ datadir=/usr/local/mysql/ datadir=/usr/local/mysql/data200The default character set used by the server is8Bit encoding latin1 character set character-set-server=utf8 # Default storage engine to be used when creating new tablesdefault-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBST ITUTION init_connect='SET NAMES utf8'
#mysqlbinlog log enabled (avoid data loss by misoperation)
server_id=2
log_bin = mysql-bin
binlog_format = ROW
expire_logs_days = 30
Copy the code

12. Initialize mysql in mysql directory

bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
Copy the code

13. Copy the service to etc and run it in mysql directory

cp ./support-files/mysql.server /etc/init.d/mysqld
Copy the code

14. Give permission

chown 777 /etc/my.cnf 
chmod +x /etc/init.d/mysqld
Copy the code

15. Restart mysql

/etc/init.d/mysqld restart
Copy the code

16. Set startup

chkconfig --level 35 mysqld on
chkconfig --list mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
service mysqld status
Copy the code

17 Add environment variables

vi /etc/profile
Copy the code

Add a line

export PATH=$PATH:/usr/local/mysql/bin
Copy the code

Exit using the command to make environment variables take effect

Source /etc/profile
Copy the code

18. Obtain the initial password

cat /root/.mysql_secret
Copy the code

Go to the /usr/local/mysql.bin directory

mysql -uroot -p
Copy the code

Enter the password obtained above to access the mysql command line

set PASSWORD = PASSWORD('New password');
Copy the code

Update the information

flush privileges;
Copy the code

Adding remote Access

use mysql;
update user set host=The '%' where user='root';
Copy the code

View user access rights

select host,user from user;
Copy the code

Create a user (custom)

create user 'xxx'@The '%' identified by '123'; 
Copy the code

Exit the mysql command line

The Exit;Copy the code

Restart mysql service (switch to /usr/local/mysql.bin)

/bin/systemctl restart  mysql.service
Copy the code
/etc/init.d/mysqld restart
Copy the code

Create a soft connection for the mysql command

ln -s /usr/local/mysql/bin/mysql   /usr/bin/mysql
Copy the code