一.软件准备
Linux系统下载地址:http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
cmake与依赖包 下载地址:https://download.csdn.net/download/qq_38118019/10394513
mysql8.0.11下载地址: https://download.csdn.net/download/qq_38118019/10394497
1.安装 gcc、gcc++
1.1 解压centOS7安装镜像文件(.iso),在Packages文件夹中找到下列rpm安装包上传至Linux服务器中
autogen-libopts-5.18-5.el7.x86_64.rpm
cpp-4.8.5-16.el7.x86_64.rpm
gcc-4.8.5-16.el7.x86_64.rpm
gcc-c++-4.8.5-16.el7.x86_64.rpm
glibc-devel-2.17-196.el7.x86_64.rpm
glibc-headers-2.17-196.el7.x86_64.rpm
kernel-headers-3.10.0-693.el7.x86_64.rpm
keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm
krb5-devel-1.15.1-8.el7.x86_64.rpm
libcom_err-devel-1.42.9-10.el7.x86_64.rpm
libmpc-1.0.1-3.el7.x86_64.rpm
libselinux-devel-2.5-11.el7.x86_64.rpm
libsepol-devel-2.5-6.el7.x86_64.rpm
libstdc++-devel-4.8.5-16.el7.x86_64.rpm
libverto-devel-0.2.5-4.el7.x86_64.rpm
mpfr-3.1.1-4.el7.x86_64.rpm
ncurses-devel-5.9-13.20130511.el7.x86_64
ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm
ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm
openssl098e-0.9.8e-29.el7.centos.3.x86_64.rpm
openssl-1.0.2k-8.el7.x86_64.rpm
openssl-devel-1.0.2k-8.el7.x86_64.rpm
openssl-libs-1.0.2k-8.el7.x86_64.rpm
pkgconfig-0.27.1-4.el7.x86_64.rpm
tcl-8.5.13-8.el7.x86_64.rpm
zlib-1.2.7-17.el7.x86_64.rpm
zlib-devel-1.2.7-17.el7.x86_64.rpm
1.2 进入CentOS下,存放上述.rpm文件的目录,执行
rpm -Uvh *.rpm --nodeps --force
2.安装cmake
tar -xzvf cmake-3.11.1.tar.gz
cd cmake-3.11.1
./bootstrap
make && make install
3.安装mysql8
3.1 创建用户密码、安装目录和数据目录
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
passwd mysql
设置新密码为:1q2w#E$R
mkdir -p /usr/local/mysql
mkdir -p /data/mysql
mkdir -p /home/mysql/run/mariadb
mkdir -p /home/mysql/log/mariadb
touch /home/mysql/run/mariadb/mariadb.log
touch /home/mysql/run/mariadb/mariadb.pid
3.2 安装mysql8
tar -zxf mysql-boost-8.0.11.tar.gz -C /usr/local
cd /usr/local/mysql-8.0.11
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.11/boost
make && make install
cd /usr/local/mysql/bin
3.3 配置my.cnf文件
vi /etc/my.cnf
[mysqld]
skip-grant-tables#这个是用来定义跳过密码,必要时添加,一般不要加
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/home/mysql/log/mariadb/mariadb.log
pid-file=/home/mysql/run/mariadb/mariadb.pid
##请根据实际情况添加参数
3.4 目录权限修改
chown -R root:root /usr/local/mysql
chown -R root:root /data/mysql
chown -R root:root /home/mysql/run/mariadb
chown -R root:root /home/mysql/log/mariadb
chmod 777 /usr/local/mysql -R
chmod 777 /data/mysql -R
chmod 755 /home/mysql/run/mariadb -R
chmod 755 /home/mysql/log/mariadb -R
3.5 初始化
./mysqld --initialize --user=mysql --datadir=/data/mysql/
(此时会自动生成一个密码比如“A temporary password is generated for root@localhost: irwyCU0
./mysql_ssl_rsa_setup
3.6 添加到启动
cp -v /usr/local/mysql/support-files/mysql.server /etc/init.d/
chkconfig --add mysql.server
3.7 启动mysql
./mysqld --defaults-file=/etc/my.cnf --user=root &
(
关闭方法为 service mysql.server stop
service mysql.server {start|stop|restart|reload|force-reload|status})
3.7.2添加软连接
ln -s /data/mysql/mysql.sock /tmp/mysql.sock
3.8 修改账号密码
/usr/local/mysql/bin/mysql -uroot -p
//密码是上面3.5生成的密码,如果密码还是怎么输都不对的话,可以修改my.cnf文件,添加skip-grant-tables参数 然后执行service mysql.server stop 关闭mysql,然后再执行./mysqld --defaults-file=/etc/my.cnf --user=root & 启动数据库,然后再执行/usr/local/mysql/bin/mysql -uroot -p登录数据库,这时就不需要密码了
mysql> alter user 'root'@'localhost' identified by "123456";
//如果启用了skip-grant-tables,则无法修改密码,此时需要修改my.cnf文件,去掉skip-grant-tables,并在另一个窗口执行service mysql.server reload,这样就可以绕过输入密码进入mysql,从而实现修改密码。后期忘记密码也可这么做。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
3.9 添加远程特账号
mysql> create user root@'%' identified by '123456';
Query OK, 0 rows affected (0.08 sec)
mysql> grant all privileges on *.* to root@'%';
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> exit
3.10 创建软链接(非必要)
ln -s /usr/local/mysql/bin/* /usr/local/bin/
mysql -h 127.0.0.1 -P 3306 -uroot -p123456 -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 8.0.11 |
+-----------+
3.11 开放Linux端口
cd /sbin
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
(
/etc/rc.d/init.d/iptables save #保存配置
/etc/rc.d/init.d/iptables restart #重启服务
保存端口开放可以使得下次服务器重启时自动开放此端口,但是centos7会报文件找不到,由于我是本地虚拟机测试用,所以不做深入研究,每次启动执行下端口开放即可
)
安装完后,如果用客户端连接,比如navicat会报1251错误,这是因为mysql8默认采用了新的加密规则,navicat暂时不支持,我们需要吧mysql8的加密规则改为旧的
4.1 配置my.cnf文件
加入default_authentication_plugin=mysql_native_password
vi /etc/my.cnf
[mysqld]
#skip-grant-tables
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql/
socket=/data/mysql/mysql.sock
default_authentication_plugin=mysql_native_passwor
default-time-zone='+8:00'
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/home/mysql/log/mariadb/mariadb.log
pid-file=/home/mysql/run/mariadb/mariadb.pid
4.2 重启mysql
service mysql.server stop
cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --user=root&
4.3 登入mysql
/usr/local/mysql/bin/mysql -uroot -p123456
4.3.1 (个人推测)由于修改了加密规则,会导致旧密码无法使用,需要先修改/etc/my.cnf 启用skip-grant-tables
4.3.2 登入 /usr/local/mysql/bin/mysql -uroot -p123456 此时能登陆成功。
(由于开启了skip-grant-tables,无法修改密码,需要再修改/etc/my.cnf 注释掉skip-grant-tables)
4.3.3 当前的mysql登陆不能退出,需要再另一个窗口重新打开Linux连接,修改/etc/my.cnf 注释掉skip-grant-tables,并执行service mysql.server reload。
4.4 重新设置密码
mysql>ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
4.5 navicat重新连接成功