源码安装mysql-5.7以上的版本

提示:MySQL从5.7版本之后,boost是必须的,建议把系统自带的boost库卸载,源码编译安装高版本
在生成环境中,安装数据库之前,需要规划好数据存储的目录
这个目录最好是一块单独的分区或者磁盘,做成raid或者LVM,编译日后磁盘的维护和扩容
对于读写比较频繁的业务,可以采用SSD等转速高的磁盘,大于13G以上才可以安装

 

规划安装目录:
安装目录: /var/lib/mysql
数据目录: /var/lib/mysql/data

 

开始安装

1、卸载以前相关MYSQL

yum -y remove mysql mariadb-*
yum -y remove boost-*

2、解决依赖

yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel

3、添加用户

useradd -M -s /sbin/nologin mysql
id mysql

4、解压

tar xf mysql-boost-5.7.19.tar.gz -C /usr/local/src/

cd /usr/local/src/mysql-5.7.19/

5、建立安装数据目录,并授予权限

mkdir -p /var/lib/mysql/data
chown -R mysql:mysql /var/lib/mysql

6、开始编译(三板斧)

cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql \
-DMYSQL_DATADIR=/var/lib/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/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=/usr/local/src/mysql-5.7.19/boost/boost_1_59_0


make -j 4 && make install

 

cat >> /etc/my.cnf <<EOF

7、写入配置文件
[mysqld]
basedir=/var/lib/mysql
datadir=/var/lib/mysql/data
port=3306
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
EOF

8、生成环境变量

 vim /etc/profile.d/mysql.sh

export PATH=/var/lib/mysql/bin:$PATH

 . /etc/profile.d/mysql.sh

 

9、生成服务启动脚本与启动

 cp /var/lib/mysql/support-files/mysql.server /etc/init.d/mysqld

 chmod +x /etc/init.d/mysqld

chown -R mysql:mysql /var/lib/mysql

 

 /var/lib/mysql/bin/mysqld --initialize --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data

 /etc/init.d/mysqld start

#  Starting MySQL.. SUCCESS!

10、安全初始化并登录

#查找mysql初始密码

cat /var/log/mysqld.log | grep  password

#  root@localhost: >4w9d<p*ecP2

启动mysql

mysql_secure_installation

-----------------------

Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

Using existing password for root.

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 50

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Success.

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Success.

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  

 - Dropping test database...

Success.

- Removing privileges on test database...

Success.

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.

All done!

---------------------------------------------------------

 

 

mysql -uroot -p密码

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| sys                |

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

4 rows in set (0.00 sec)

posted @ 2019-08-29 15:22  科子  阅读(267)  评论(0编辑  收藏  举报