添加国内源:mysql | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
注意:5.7安装之后有一个临时密码,进行登录并修改新密码后才可以对mysql进行操作。
可以yun list看看各个系统光盘自带的都是什么版本,或者什么分支(mysql/mariadb)。
[root@ctos79 mysql 09:04:29]#yum list | grep mariadb
mariadb-libs.x86_64 1:5.5.68-1.el7 @anaconda
mariadb.x86_64 1:5.5.68-1.el7 BaseOS
mariadb-bench.x86_64 1:5.5.68-1.el7 BaseOS
mariadb-devel.i686 1:5.5.68-1.el7 BaseOS
mariadb-devel.x86_64 1:5.5.68-1.el7 BaseOS
mariadb-embedded.i686 1:5.5.68-1.el7 BaseOS
mariadb-embedded.x86_64 1:5.5.68-1.el7 BaseOS
mariadb-embedded-devel.i686 1:5.5.68-1.el7 BaseOS
mariadb-embedded-devel.x86_64 1:5.5.68-1.el7 BaseOS
mariadb-libs.i686 1:5.5.68-1.el7 BaseOS
mariadb-server.x86_64 1:5.5.68-1.el7 BaseOS
mariadb-test.x86_64 1:5.5.68-1.el7 BaseOS
yum -y install libaio numactl-libs ncurses-compat-libs
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -s mysql-5.7.44-linux-glibc2.12-x86_64 mysql
chown -R root.root /usr/local/mysql/
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
cp /etc/my.cnf{,.bak}
cat > /etc/my.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
mkdir -pv /data/mysql
# 随机密码
mysqld --initialize --user=mysql --datadir=/data/mysql
awk '/temporary password/{print $NF}' /data/mysql/mysql.log
vp-jEZe,K4lg
# 空密码
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
# 修改root密码
mysqladmin -uroot -p'vp-jEZe,K4lg' password 123456
# 如果前面为空密码
mysqladmin -uroot password 123456
[root@ctos79 mysql 03:56:50]#mysql -uroot -p123456
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 4
Server version: 5.7.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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>
编译 make -j 8 多线程编译
5.6还是需要执行安全加固的。
yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel \
libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel \
openssl-devel libevent-devel libaio-devel perl-Data-Dumper
useradd -r -s /sbin/nologin -d /data/mysql mysql
mkdir /data/mysql -p
chown mysql.mysql /data/mysql
yum install -y unzip
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.44.zip
unzip mysql-5.7.44.zip
mv mysql-5.7.44 /usr/local/src/
cd /usr/local/src/mysql-5.7.44/
# 编译前需要升级boost库,否则会报错
wget https://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar -xf boost_1_59_0.tar.gz
cd boost_1_59_0
./bootstrap.sh --prefix=/usr/local
./b2 install --with=all
---这里安装实测执行了10分钟---
cmake . \
-DCMAKE_INSTALL_PREFIX=/apps/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make -j 8 && make install
---开8线程的编译安装时间实测是6分钟---
如果出错,执行rm -f CMakeCache.txt
echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
cd /apps/mysql/
~~# bin/mysql_install_db --datadir=/data/mysql/ --user=mysql~~
bin/mysqld --initialize --user=mysql --datadir=/data/mysql
# 如果执行报错,说明数据库文件目录不为空
mv /data/mysql/* /tmp
记住生成的临时密码:r#x?yudwb3lX
cp /etc/my.cnf{,.bak}
cat > /etc/my.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
mysqladmin -uroot -p'r#x?yudwb3lX' password 123456
root@ctos79 mysql 09:00:13]#mysql -uroot -p123456
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 6
Server version: 5.7.44 Source distribution
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
也可以使用docker进行安装,拉镜像就好了。