1、下载依赖包
yum -y install ncurses-devel cmake make apr* autoconf automake curl curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* cpp glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* php-common php-gd gettext gettext-devel ncurses* libtool* libxml2 libxml2-devel patch policycoreutils bison
2、添加用户组和工作目录
groupadd mysql
useradd -r -g mysql mysql
mkdir /usr/local/mysql
mkdir /data/mysqldb
3、编译安装mysql
cd /usr/local/src/
tar -zvxf mysql-5.7.9.tar.gz
cd mysql-5.7.9
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_USER=mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
由于需要boost库的支持才能安装,下载出现问题,所以手动下载boost包,
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
# mkdir /usr/local/boost
然后解压到/usr/local/boost
tar zxvf boost_1_59_0.tar.gz -C /usr/local/boost
make && make install
4、设置权限并初始化MySQL系统授权表
cd /usr/local/mysql
chown -R mysql . ---更改所有者,注意是mysql .
chgrp -R mysql . ---改所属组,注意是mysql .
######配置开机自启动
[root@typecodes mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@typecodes mysql]# chmod +x /etc/init.d/mysqld #增加可执行权限
[root@typecodes mysql]# chkconfig --add mysqld #添加到sysV服务
[root@typecodes mysql]# chkconfig mysqld on
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb //初始化数据库
记住临时密码
5、启动MySQL服务
[root@typecodes mysql]# service mysqld start
6、配置Mysql系统环境变量
# vi /etc/profile ---编辑/etc/profile文件在最后添加如下两行
PATH=/usr/local/mysql/bin:$PATH
export PATH ---不加登录mysql时会报错“-bash: mysql: command not found”
# source /etc/profile ---使环境变量及时生效
7、访问MySQL数据库
# mysql -u root -h 127.0.0.1 -p ---连接mysql,输入初始化时生成的随机密码
mysql> alter user 'root'@'localhost' identified by 'password'; ---修改root新密码
mysql>quit; ---退出也可用exit;
# myslq -u root -p ---重新登录时输入新的密码回车
8、创建SSL/RSA文件
# cd /usr/local/mysql/bin ---切换目录
# mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb ---创建新的SSL文件
FAQ:由于安装好后,并没有出现root的随机密码,无奈之下,查找各种原因,发现是mysql的配置文件中有问题;
其中我在client和mysqld服务中都定义了socket,可是两个的路径却不一样,重新配置my.cnf,
socket =/tmp/mysql.sock #全部改为这个路径,
然后再[mysqld]字段下增加配置
skip-grant-tables
然后重启mysqld服务
service mysqld restart
再重置root密码
mysql> use mysql
mysql>update mysql.user set authentication_string=password('root') where user='root';
mysql>flush privileges;
修改my.cnf
重启数据库;
发现重新退出后,还是说不行,提示错误:
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
这样登录/usr/local/mysql/bin/mysql -u root -proot
然后重置密码
mysql> set password = password('000000');
mysql> alter user 'root'@'localhost' password expire never;
mysql> flush privileges;