一、下载MySQL5.6.38安装包

下载地址:https://www.mysql.com/downloads/  打开网站之后选择Archives

CentOS7 编译安装MySQL5.6.38(一)-LMLPHP

然后再选择开源版本

CentOS7 编译安装MySQL5.6.38(一)-LMLPHP

选择我们要下载的版本:

https://downloads.mysql.com/archives/community/

CentOS7 编译安装MySQL5.6.38(一)-LMLPHP

二、编译安装MySQL5.6.38

# cat /etc/redhat-release
CentOS Linux release 7.2. (Core) # 创建系统帐号
# groupadd -r mysql
# useradd -r -g mysql -s /sbin/nologin mysql # 关闭SELinux
# setenforce
# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config # 安装依赖包
# yum install ncurses-devel libaio-devel -y
# yum install cmake gcc gcc-c++ make autoconf -y # 上面如果没有下载安装包,可直接wget下载
# wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.38.tar.gz # tar xf mysql-5.6..tar.gz
# cd mysql-5.6./ # 进行编译安装
[ ~/mysql-5.6.]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6. \ # 指定安装目录
-DMYSQL_DATADIR=/usr/local/mysql-5.6./data \ # 指定数据目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6./mysql.sock \ # 指定sock文件位置
-DDEFAULT_CHARSET=utf8 \ # 默认字符集
-DDEFAULT_COLLATION=utf8_general_ci \ # 默认编码
-DWITH_EXTRA_CHARSETS=all \ # 其它额外字符集
-DWITH_INNOBASE_STORAGE_ENGINE= \ # 支持的存储引擎
-DWITH_FEDERATED_STORAGE_ENGINE= \
-DWITH_BLACKHOLE_STORAGE_ENGINE= \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE= \
-DWITH_SSL=bundled \ # 编译其它功能SSL、ZLIB等
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE= \
-DWITH_EMBEDDED_SERVER= \
-DENABLE_DOWNLOADS= \
-DWITH_DEBUG= -DSYSCONFDIR=/etc
[ ~/mysql-5.6.]# make && make install # 编译并安装数据库 # 做软链接并给MySQL目录授权
# ln -s /usr/local/mysql-5.6./ /usr/local/mysql
# chown -R mysql.mysql /usr/local/mysql

三、初始化数据目录

# MySQL .6初始化数据库的命令:
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data -user=mysql # MySQL .7初始化数据库的命令:
# /usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data -user=mysql

四、拷贝启动服务的脚本

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod /etc/init.d/mysqld

五、改环境变量

# echo 'PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
# source /etc/profile

六、改配置文件,并启动数据库

# vim /etc/my.cnf
[mysqld]
server_id=
port=
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
log_bin=/usr/local/mysql/mysql-bin
log_error=/var/log/mysql.log
character-set-server=utf8 [client]
socket=/usr/local/mysql/mysql.sock
# /etc/init.d/mysqld start

七、设置数据库密码并清空MySQL不安全帐号

# mysqladmin -u root password
# mysql -uroot -p123456 # 清除不安全的用户,先查询用户名为空和没有密码的
> select user,password,host from mysql.user;
> drop user root@'127.0.0.1';
> drop user ''@'localhost';
05-11 18:08
查看更多