1)基于源码包安装MySQL
[root@localhost ~]# rpm -q mysql mysql-server mariadb mairadb-server //检查有没有安装rpm格式的包有就要卸载掉
ncurses-devel是cmake的依赖包
[root@localhost ~]#yum -y install ncurses-devel cmake
[root@localhost ~]#rpm -q ncurses-devel cmake
导入mysql软件包(mysql-5.7.24.tar)
[root@localhost ~]#tar xf mysql-5.7.24.tar.gz -C /usr/src/
[root@localhost ~]#cd /usr/src/mysql-5.7.24/
[root@localhost 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的文件夹
[root@localhost mysql-5.7.24]#mkdir /usr/local/boost
b.进入目录并下载boost
[root@localhost mysql-5.7.24]# cd /usr/local/boost/
[root@localhost boost]# 导入boost软件包(boost_1_59_0.tar)
[root@localhost boost]#tar xf boost_1_59_0.tar
[root@localhost boost]#cd /usr/src/mysql-5.7.24/
[root@localhost mysql-5.7.24]# yum -y install gcc gcc-c++
[root@localhost 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)安装后的调整
对数据库目录进行权限设置
[root@localhost mysql-5.7.24]# chown -R mysql:mysql /usr/local/mysql
[root@localhost 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)初始化数据库
[root@localhost 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 root@localhost: FUWehrKBq0(6 //FUWehrKBq0(6是密码
4)设置环境变量
[root@localhost mysql-5.7.24]# vim /etc/profile
因为写的是绝对路径也没有修改PATH值所以必须在尾部添加PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql-5.7.24]# source /etc/profile //因为profile是脚本所以必须用source使其生效
5)添加系统服务
添加MySQL为系统服务,以便通过systemctl命令进行管理
[root@localhost mysql-5.7.24]# cp /usr/src/mysql-5.7.24/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.7.24]# chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.7.24]# /etc//init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql.log'.
SUCCESS!
[root@localhost mysql-5.7.24]# netstat -anpt | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 82911/mysqld
[root@localhost mysql-5.7.24]# mysql -u root -p'FUWehrKBq0(6' //进入到mysql后台
mysql> exit //输入exit退出mysql后台
Bye
[root@localhost mysql-5.7.24]# mysqladmin -u root -p'FUWehrKBq0(6' password '123456' //修改mysql密码将FUWehrKBq0(6换成123456(后期修改数据库用户的密码:)
[root@localhost mysql-5.7.24]# netstat -anpt | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 82911/mysqld
MYSQL安装完成
修改mysql字符集使得支持中文
在mysqld列中添加如下命令
[mysqld] character_set_server=utf8进
进入数据库查看
mysql> show variables like 'char%';
+--------------------------+-----------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.5.32/share/charsets/ |
+--------------------------+-----------------------------------------+
8 rows in set (0.00 sec)