One, CentOS7.4 system comes with mariadb
# View the Mariadb that comes with the system
[ root@vmtest ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
# Uninstall Mariadb that comes with the system
[ root@vmtest ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
# Delete my in the etc directory.cnf
[ root@vmtest ~]# rm /etc/my.cnf
# Check if mysql exists
[ root@VMTest ~]# rpm -qa | grep mysql
[ root@VMTest ~]#
Three, check whether users and groups exist
1 ) Check if the mysql combined user exists
# Check if the mysql group and user exist, if not, create
[ root@VMTest ~]# cat /etc/group | grep mysql
[ root@VMTest ~]# cat /etc/passwd | grep mysql
# Query all users (just record, no need to execute)
[ root@VMTest ~]# cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F ":"'{print $1 "|" $3 "1" $4}'| more
root|010
sync|510
mysql|99711001
2 ) If it does not exist, create the mysql group and user
# Create mysql user group
[ root@VMTest ~]# groupadd mysql
# Create a user named mysql and join the mysql user group
[ root@VMTest ~]# useradd -g mysql mysql
# Set the password to 111111[root@VMTest ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype newpassword:
passwd: all authentication tokens updated successfully.
Fourth, download the tar package of mysql
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
# enter/usr/local/src folder
[ root@VMTest ~]# cd /usr/local/src/
# Upload mysql TAR package
[ root@VMTest src]# rz
# Unzip the tar file
[ root@VMTest src]# tar xvf mysql-5.7.22-el7-x86_64.tar
# Unzip mysql-5.7.22-el7-x86_64.tar.gz
[ root@VMTest src]# tar -zxvf mysql-5.7.22-el7-x86_64.tar.gz
# Move the decompressed file to/usr/local folder
[ root@VMTest src]# mv mysql-5.7.22-el7-x86_64 /usr/local
# enter/usr/Under local, modify to mysql
[ root@VMTest src]# cd /usr/local
[ root@VMTest local]# mv mysql-5.7.22-el7-x86_64 mysql
Six, change the group and user belonging to
# Change the group and user you belong to
[ root@VMTest local]# chown -R mysql mysql/[root@VMTest local]# chgrp -R mysql mysql/[root@VMTest local]# cd mysql/[root@VMTest mysql]# mkdir data
[ root@VMTest mysql]# chown -R mysql:mysql data
Seven, enter the mysql folder, and install mysql
# Enter mysql
[ root@VMTest etc]# cd /usr/local/mysql/
# Install mysql
[ root@VMTest mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/or(recommend):[root@VMTest mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/2018-07-0415:46:02[WARNING] 5mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018- 07- 0415:46:05[ WARNING] The bootstrap log isn't empty:2018-07-0415:46:05[WARNING]2018-07-04T15:46:02.728710Z 0[Warning]--bootstrap is deprecated. Please consider using --initialize instead
2018- 07- 01 T15:46:02.729161Z 0[Warning] Changed limits: max_open_files:1024(requested 5000)2018-07-04 T15:46:02.729167Z 0[Warning] Changed limits: table_open_cache:407(requested 2000)
[ root@VMTest mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[ root@VMTest mysql]# chown 777/etc/my.cnf
[ root@VMTest mysql]# chmod +x /etc/init.d/mysqld
# enter/etc folder
[ root@VMTest mysql]# cd /etc
# Create my.cnf file
[ root@VMTest etc]# touch my.cnf
# Edit my.cnf
[ root@VMTest etc]# vim my.cnf
1 ) My.cnf add the following content:
[ mysql]
# Set the default character set of the mysql client
default-character-set=utf8
[ mysqld]
# Set 3306 port
port =3306
# Set mysql installation directory
basedir=/usr/local/mysql
# Set the storage directory of the mysql database data
datadir=/usr/local/mysql/data
# Maximum number of connections allowed
max_connections=200
# The character set used by the server defaults to the 8-bit encoding latin1 character set
character-set-server=utf8
# The default storage engine that will be used when creating new tables
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
2 ) View the content of my.cnf
# View my.cnf file
[ root@VMTest mysql]# cat /etc/my.cnf
Nine, start mysql
# Start mysql
[ root@VMTest mysql]# /etc/init.d/mysqld start
or
[ root@VMTest mysql]# ./mysqld --defaults-file=/etc/my.cnf --user=root
MySQL manager or server PID file could not be found![FAILED]
solve:
# 1、 View process
[ root@VMTest mysql]# ps aux|grep mysql
root 100310.00.11132641616 pts/0 S 14:360:00/bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/iZ2ze3hm3gyjyjz628l7rgZ.pid
mysql 102200.019.11140876195072 pts/0 Sl 14:360:02/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=iZ2ze3hm3gyjyjz628l7rgZ.err --pid-file=/usr/local/mysql/data/iZ2ze3hm3gyjyjz628l7rgZ.pid --port=3306
root 104210.00.0112660968 pts/0 R+15:510:00 grep --color=auto mysql
# 2、 Kill process
[ root@VMTest mysql]# kill -910031[root@VMTest mysql]# kill -910220
# 3、 Restart mysql
[ root@VMTest mysql]# /etc/init.d/mysqld restart
Shutting down MySQL..
Starting MySQL.
Ten, set to boot
# Set boot up
[ root@VMTest mysql]# chkconfig --level 35 mysqld on
[ root@VMTest mysql]# chkconfig --list mysqld
[ root@VMTest mysql]# chmod +x /etc/rc.d/init.d/mysqld
[ root@VMTest mysql]# chkconfig --add mysqld
[ root@VMTest mysql]# chkconfig --list mysqld
[ root@VMTest mysql]# service mysqld status
SUCCESS! MySQL running(4475)
# enter/etc/profile folder
[ root@VMTest mysql]# vim /etc/profile
1 ) Modify /etc/profile and add the following at the end
# modify/etc/profile file
# set mysql environment
export PATH=$PATH:/usr/local/mysql/bin
# Make the file effective
[ root@VMTest mysql]# source /etc/profile
Twelve, get mysql initial password
# 1、 Get mysql initial password
[ root@VMTest bin]# cat /root/.mysql_secret
# Password setfor user 'root@localhost' at 2017-04-1717:40:02
_ pB*3VZl5T<6
# 2、 change Password
[ root@VMTest bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with; or \g.
Your MySQL connection id is 53
Server version:5.7.22 MySQL Community Server(GPL)Copyright(c)2000,2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
mysql>set PASSWORD =PASSWORD('root');
Query OK,0 rows affected,1warning(0.00 sec)
mysql> flush privileges;
Query OK,0 rows affected(0.01 sec)
# Add remote access permissions
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-A
Database changed
mysql> update user set host='%' where user='root';
Query OK,0 rows affected(0.00 sec)
Rows matched:1 Changed:0 Warnings:0
mysql> select host,user from user;+-----------+---------------+| host | user |+-----------+---------------+|%| root || localhost | mysql.session || localhost | mysql.sys |+-----------+---------------+3 rows inset(0.00 sec)
# Restart mysql
[ root@VMTest bin]# /etc/init.d/mysqld restart
Shutting down MySQL..
Starting MySQL.
Remarks:
As installed in/usr/mysql under local, so mysql can be started in any folder
If it is installed in another folder, execute the following command:
# In order to log in to mysql in any directory
ln -s /Your mysql path/mysql /usr/local/mysql
15、 Verification, you may need to turn off the firewall
Service iptables stop
Recommended Posts