centos 7源码安装mysql5.7

安装软件依赖

[root@localhost src]# yum install boost gcc ncurses-devel libaio bison gcc-c++ git cmake ncurses-devel openssl openssl-devel –y

下载安装boost源码包

[root@localhost src]# wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz -O /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# tar -xvf boost_1_59_0.tar.gz
[root@localhost local]# mv  boost_1_59_0 boost

下载安装mysql源码包

[root@localhost src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.28.tar.gz

解压:

[root@localhost src]# tar -xvf mysql-5.7.28.tar.gz

预编译

[root@localhost src]# cd mysql-5.7.28
[root@localhost mysql-5.7.28]#cmake .  \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 \
 -DMYSQL_UNIX_ADDR=/data/mysql57/mysql.sock \
 -DMYSQL_DATADIR=/data/mysql57 \
 -DSYSCONFDIR=/usr/local/mysql57 \
 -DMYSQL_USER=mysql \
 -DMYSQL_TCP_PORT=3306 \
 -DWITH_XTRADB_STORAGE_ENGINE=1 \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITH_PARTITION_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DWITH_MYISAM_STORAGE_ENGINE=1 \
 -DWITH_READLINE=1 \
 -DENABLED_LOCAL_INFILE=1 \
 -DWITH_EXTRA_CHARSETS=1 \
 -DDEFAULT_CHARSET=utf8  \
 -DDEFAULT_COLLATION=utf8_general_ci  \
 -DEXTRA_CHARSETS=all \
 -DWITH_BIG_TABLES=1 \
 -DWITH_DEBUG=0 \
 -DENABLE_DTRACE=0 \
 -DDOWNLOAD_BOOST=1 \
 -DWITH_BOOST=/usr/local/boost

编译安装

[root@localhost mysql-5.7.28]# make
[root@localhost mysql-5.7.28]# make install

创建数据目录

[root@localhost mysql-5.7.28]# mkdir -p /data/mysql57

新建mysql用户且不能登录操作系统

[root@localhost mysql-5.7.28]# useradd -s /sbin/nologin mysql

将数据目录权限纵给mysql用户

[root@localhost mysql-5.7.28]# chown -R mysql. /data/mysql57

新建启动二进制文件

[root@localhost mysql-5.7.28]# cp support-files/mysql.server /etc/init.d/mysqld57

给二进制文件加可执行权限

[root@localhost mysql-5.7.28]# chmod +x /etc/init.d/mysqld57

创建mysql配置文件my.cnf

[root@localhost mysql-5.7.28]# vim /usr/local/mysql57/my.cnf
[mysqld]
basedir=/usr/local/mysql57/
datadir=/data/mysql57/
port=3306
pid-file=/data/mysql57/mysql.pid
socket=/data/mysql57/mysql.sock

[mysqld_safe]
log-error=/data/mysql57/mysql.log

初使化mysql

[root@localhost mysql-5.7.28]# /usr/local/mysql57/bin/mysqld --initialize --user=mysql --datadir=/data/mysql57 --basedir=/usr/local/mysql57

启动mysql

[root@localhost mysql-5.7.28]# /etc/init.d/mysqld57 start
Starting MySQL.Logging to '/data/mysql57/mysql.log'.
 SUCCESS!

免密登录及更新root密码

[root@localhost mysql-5.7.28]# pkill mysql
[root@localhost mysql-5.7.28]# /usr/local/mysql57/bin/mysqld_safe --user=mysql --skip-grant-tables &
[1] 24027
[root@localhost mysql-5.7.28]# 2020-05-30T12:27:19.394792Z mysqld_safe Logging to '/data/mysql57/mysql.log'.
2020-05-30T12:27:19.434493Z mysqld_safe Starting mysqld daemon with databases from /data/mysql57
[root@localhost mysql-5.7.28]# /usr/local/mysql57/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 Source distribution

Copyright (c) 2000, 2019, 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.

更新root密码
mysql> update mysql.user set authentication_string=password("123456") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

关闭mysql服务

[root@localhost mysql-5.7.28]# /etc/init.d/mysqld57 stop

启动mysql

[root@localhost mysql-5.7.28]# /etc/init.d/mysqld57 start

登录

[root@localhost mysql-5.7.28]# /usr/local/mysql57/bin/mysql -u root -p
Enter password:     #123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28

Copyright (c) 2000, 2019, 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>

将mysql设置为系统服务,并开机启动

[root@localhost ~]# chkconfig --add mysqld57
[root@localhost ~]# chkconfig --level 35 mysqld57 on

Mysql安全设置
/usr/local/mysql57/bin/mysql_secure_installation

[root@localhost ~]# /usr/local/mysql57/bin/mysql_secure_installation
[root@localhost ~]# /usr/local/mysql57/bin/mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:  输入root密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 25 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : NO

 ... skipping.
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  删除test库
 - 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!

------------------end

猜你喜欢

转载自blog.csdn.net/oToyix/article/details/106452587