1)基于源码包安装MySQL
[[email protected] ~]# rpm -q mysql mysql-server mariadb mairadb-server //检查有没有安装rpm格式的包有就要卸载掉
ncurses-devel是cmake的依赖包
[[email protected] ~]#yum -y install ncurses-devel cmake
[[email protected] ~]#rpm -q ncurses-devel cmake
导入mysql软件包(mysql-5.7.24.tar)
[[email protected] ~]#tar xf mysql-5.7.24.tar.gz -C /usr/src/
[[email protected] ~]#cd /usr/src/mysql-5.7.24/
[[email protected] mysql-5.7.24]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc&& make && make install
此时会报一个boost错误!
a.解决办法在/usr/local下创建一个名为boost的文件夹
[[email protected] mysql-5.7.24]#mkdir /usr/local/boost
b.进入目录并下载boost
[[email protected] mysql-5.7.24]# cd /usr/local/boost/
[[email protected] boost]# 导入boost软件包(boost_1_59_0.tar)
[[email protected] boost]#tar xf boost_1_59_0.tar
[[email protected] boost]#cd /usr/src/mysql-5.7.24/
[[email protected]t mysql-5.7.24]# yum -y install gcc gcc-c
[[email protected] mysql-5.7.24]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc -DWITH_BOOST=/usr/local/boost && make && make install
2)安装后的调整
对数据库目录进行权限设置
[[email protected] mysql-5.7.24]# chown -R mysql:mysql /usr/local/mysql
[[email protected] mysql-5.7.24]# vim /etc/my.cnf
修改如下四处 datadir=/usr/local/mysql/data socket=/tmp/mysql.sock log-error=/usr/local/mysql/data/mysql.log //错误日志存放位置 pid-file=/usr/local/mysql/data/mysql.pid //PID的值存放位置
3)初始化数据库
[[email protected] mysql-5.7.24]# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2019-09-11T08:01:40.678278Z 1 [Note] A temporary password is generated for [email protected]: FUWehrKBq0(6 //FUWehrKBq0(6是密码
4)设置环境变量
[[email protected] mysql-5.7.24]# vim /etc/profile
因为写的是绝对路径也没有修改PATH值所以必须在尾部添加PATH=$PATH:/usr/local/mysql/bin
[[email protected] mysql-5.7.24]# source /etc/profile //因为profile是脚本所以必须用source使其生效
5)添加系统服务
添加MySQL为系统服务,以便通过systemctl命令进行管理
[[email protected] mysql-5.7.24]# cp /usr/src/mysql-5.7.24/support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql-5.7.24]# chmod x /etc/init.d/mysqld
[[email protected] mysql-5.7.24]# /etc//init.d/mysqld start
Starting MySQL.Logging to ‘/usr/local/mysql/data/mysql.log‘.
SUCCESS!
[[email protected] mysql-5.7.24]# netstat -anpt | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 82911/mysqld
[[email protected] mysql-5.7.24]# mysql -u root -p‘FUWehrKBq0(6‘ //进入到mysql后台
mysql> exit //输入exit退出mysql后台
Bye
[[email protected] mysql-5.7.24]# mysqladmin -u root -p‘FUWehrKBq0(6‘ password ‘123456‘ //修改mysql密码将FUWehrKBq0(6换成123456(后期修改数据库用户的密码:)
[[email protected] mysql-5.7.24]# netstat -anpt | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 82911/mysqld
MYSQL安装完成