编译安装mysql
# 安装依赖包和开发工具包
yum -y install libevent* libtool* autoconf* libstd* ncurse* bison* openssl* gcc gcc-c++ bzip2*
yum -y groupinstall "Development Tools"
# 下载cmake编译工具
[root@96 ~]# cd /usr/src/
[root@96 src]# wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
下载过程略。。。
[root@96 src]# ls
cmake-2.8.12.1.tar.gz
# 解压
[root@96 src]# tar xf cmake-2.8.12.1.tar.gz
[root@96 src]# ls
cmake-2.8.12.1 cmake-2.8.12.1.tar.gz
# 编译安装cmake
[root@96 ~]# cd /usr/src/cmake-2.8.12.1
[root@96 cmake-2.8.12.1]# ./configure && make && make install
# 安装boost
wget -O /usr/local/boost_1_59_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
cd /usr/local
tar xf boost_1_59_0.tar.gz
mv boost_1_59_0.tar.gz boost
# 编译安装mysql5.7.26
[root@96 cmake-2.8.12.1]# cd /usr/src/
[root@96 src]# wget http://downloads.mysql.com/archives/get/file/mysql-5.7.26.tar.gz
[root@96 src]# ls
cmake-2.8.12.1 cmake-2.8.12.1.tar.gz kernels mysql-5.7.26.tar.gz
[root@96 src]# tar xf mysql-5.7.26.tar.gz
[root@96 src]# cd mysql-5.7.26
[root@96 mysql-5.7.26]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/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/boost
编译过程略.....
[root@96 mysql-5.7.26]# make && make install
# 创建mysql用户和组
[root@96 mysql-5.7.26]# groupadd mysql
[root@96 mysql-5.7.26]# useradd -M -s /sbin/nologin -g mysql mysql
# 设置环境变量
[root@96 mysql-5.7.26]# cd /usr/local/mysql/
[root@96 mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
[root@96 mysql]# . /etc/profile.d/mysql.sh
# 初始化数据库
[root@96 mysql]# mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
2019-08-17 17:29:43 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-08-17 17:29:45 [WARNING] The bootstrap log isn't empty:
2019-08-17 17:29:45 [WARNING] 2019-08-17T09:29:43.936116Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2019-08-17T09:29:43.936687Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2019-08-17T09:29:43.936692Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
# 修改配置文件
[root@96 mysql]# sed -i '11,13d' /etc/my.cnf
[root@96 mysql]# sed -ri 's#^(datadir=).*#\1/usr/local/mysql/data#g' /etc/my.cnf
[root@96 mysql]# sed -ri 's#^(socket=).*#\1/tmp/mysql.sock#g' /etc/my.cnf
# 设置服务启动脚本
[root@96 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@96 mysql]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@96 mysql]# sed -ri 's#^(datadir=).*#\1/usr/local/mysql/data#g' /etc/init.d/mysqld
# 启动服务
[root@96 mysql]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/96.err'.
SUCCESS!
[root@96 mysql]# chkconfig mysqld on
[root@96 mysql]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
上面已经安装好了mysql但是没有密码登录所以需要破解密码:
mysql破解密码
# 编辑配置文件
[root@96 ~]# echo "skip-grant-tables" >> /etc/my.cnf
[root@96 ~]# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
[root@96 ~]# mkdir /var/lib/mysql
[root@96 ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
# 不使用密码登录进去
[root@96 ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 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.
mysql> use mysql; #进去mysql数据库
mysql> update user set authentication_string = password('shicailun666!') where User = 'root'; #重置mysql密码
mysql> quit #退出
Bye
[root@96 ~]# sed -i /skip-grant-tables/d /etc/my.cnf # 将配置文件中跳过授权表删除
# 重启服务
[root@96 ~]# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
# 使用新密码登录
[root@96 ~]# mysql -uroot -p'shicailun666!'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26
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>