A tutorial for installing mysql under centos7
- 2021-11-29 16:48:08
- OfStack
Recently, I plan to deploy a cloud disk on my home server, so I started a series of environment building operations. When I installed mysql, I found that there were some differences, so I recorded them to avoid searching everywhere like today next time.
1. Uninstall older versions
Use the following command to check if MySQL Server is installed
rpm -qa | grep mysql
If so, uninstall it by the following command
rpm -e mysql // Normal delete mode
rpm -e --nodeps mysql // Forceful Delete Mode. If you are prompted to have other files that you depend on when you delete them with the above command, you can use this command to forcefully delete them
2: Install MySQL
1. Install dependencies
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
2. Get the source code (it is recommended to download http://mirrors.sohu.com/mysql from the mirror image of sohu in China...
boost library is required for mysql 5.7. It is difficult to find a suitable version on the Internet. It is recommended to download the mysql version with boost library directly
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.24.tar.gz
tar xvf mysql-boost-5.7.24.tar.gz
cd mysql-5.7.24
3. Compile and install
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost
make && make install
For compiled parameters, please refer to http://dev. mysql. com/doc/refm....
3: Configure MySQL
Use the following command to see if there are mysql users and user groups
cat /etc/passwd # View a list of users
cat /etc/group # View a list of user groups
If not, create
groupadd mysql
useradd -g mysql mysql
Modify the/usr/local/mysql permissions
chown -R mysql:mysql /usr/local/mysql
mysql5.7.18 The default will no longer be provided in the future mysql Configuration file, here we can find it online again 1 Simple configuration ,
vi /etc/my.cnf And then write to 1 Below
[client]
port = 3306
default-character-set=utf8
[mysqld]
# 1 General configuration options
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character-set-server=utf8
default_storage_engine = InnoDB
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Configure service scripts
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on # Add to boot entry
service mysql start # Start mysql
Will mysql Execute file to path Directory ,vi /etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
Then execute source/etc/profile
4: Initialize mysql
1. Execute the initialization script (mysql root password will be generated in the last line after successful initialization, or you can initialize an account with an empty password with./mysqld-initialize-insecure)
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
...
2019-04-11T14:34:15.922856Z 1 [Note] A temporary password is generated for root@localhost: /rTmud(Th5Yy
2. The firewall opens port 3306
The method for adding ports in Firewalld is as follows:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
Summarize