Centos7 install mysql5.7.13

Check if mysql is installed:

mysql --version

 mysql  Ver 14.14 Distrib 5.7.13, for Linux (x86_64) using  EditLine wrapper

Check if cmake is installed:

Enter the command: cmake -help

3. Install the cmake package

# wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz

# tar zxvf cmake-3.5.2.tar.gz

# cd cmake-3.5.2/

# ./bootstrap

# gmake

# gmake install 

 

4. Create mysql installation directory and database storage directory

# mkdir -p /usr/local/mysql //Install mysql

# mkdir -p /usr/local/mysql/data //Store the database

 

5. Add users and create database directories and permission settings

#groupadd mysql

#useradd -r -g mysql mysql

 

6. MYSQL 5.7.13 installation

 

#cd  /usr/local

#wget http://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

#tar zvxf boost_1_59_0.tar.gz

#mv boost_1_59_0  boost

#cd / opt

#wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.13.tar.gz

# tar zxvf mysql-5.7.13.tar.gz

# cd mysql-5.7.13

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=/usr/local/boost

# gmake

# gmake install

 

Parameter Description:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //Installation directory

-DINSTALL_DATADIR=/usr/local/mysql/data //Database storage directory

-DDEFAULT_CHARSET=utf8 //Use utf8 characters

-DDEFAULT_COLLATION=utf8_general_ci //check character

-DEXTRA_CHARSETS=all //Install all extended character sets

-DENABLED_LOCAL_INFILE=1 //Allow data to be imported from local

Precautions:

When recompiling, old object files and cache information need to be cleared.

# make clean

# rm -f CMakeCache.txt

# rm -rf /etc/my.cnf

# cd /usr/local/mysql

 

7. Configuration

(1) Set directory permissions

# cd /usr/local/mysql

# chown -R root:mysql . //Set the owner of all files in the current directory to root and the group to mysql

# chown -R mysql:mysql data

(2)  Start the service added to the system

# cp support-files/my-default.cnf /etc/my.cnf //Add the mysql startup service to the system service

(3) Create a table of the system database

# cd /usr/local/mysql

# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

(4) Set environment variables

# vi /root/.bash_profile

Add parameters to PATH=$PATH:$HOME/bin as:

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

#source /root/.bash_profile

(5) Start mysql

# cd /usr/local/mysql

 

# cp support-files/mysql.server /etc/init.d/mysql //Add the mysql startup service to the system service

# chkconfig --add mysql # Add to system service

# chkconfig mysql on # Boot up

# service mysql start

 

# ln -s /usr/local/mysql/bin/mysql /usr/bin

 ————————Set up account ————————————

[root@gj mysql]# mysql -u root -p

 

Enter password: The initial password is empty, press Enter

 

mysql> set password for root@localhost = password('123456');

 

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

mysql> update user set host = '%' where user = 'root';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

 

mysql> flush privileges;

 

Query OK, 0 rows affected (0.00 sec)

 

mysql> select host, user from user;

+-----------+-----------+

| host      | user      |

+-----------+-----------+

| %         | root      |

| localhost | mysql.sys |

+-----------+-----------+

 

2 rows in set (0.00 sec)

 

 

 

set global max_allowed_packet = 2*1024*1024*10;

 

------------------------------------------Security Settings------ --------------------------------

Create the database:

 

create database database name default charset utf8 collate utf8_general_ci;

 

 Create a user test with least privilege

create user 'test'@'%' IDENTIFIED by '123456';

grant select,insert,update,delete,create,drop,alter on database name.* to 'test'@'%';

grant lock tables on  database name.* to 'test'@'%';

flush privileges;

 

Modify the root user name and password to restrict remote access

update mysql.user set user="admin" where user="root";

flush privileges; 

update user set host='localhost' where user='admin';

flush privileges;//Only root is allowed to log in locally

SET PASSWORD FOR 'admin'@'localhost' = PASSWORD('complex password');

flush privileges; 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326841657&siteId=291194637