一、mysql5.7源码安装
1.清除卸载原mysql
[root@192 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@192 ~]# yum -y remove mari*
或者用rpm卸载
[root@192 ~]#rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
[root@192 ~]# rm -rf /var/lib/mysql/*
1.解决依赖包并下载源码包至/home/soft/目录下
yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison
cd /opt/
mysql源码下载安装.note http://note.youdao.com/noteshare?id=08c9c77075257b9296b79654148cef4e&sub=F4D7C6B5CCFE478A97B346A459F4A24B 下载mysql源码包
tar -xzvf mysql-boost-5.7.18.tar.gz
2、新建MySQL用户和用户组,创建/data/mysql 目录存放mysql数据
mkdir /usr/local/mysql
groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
mkdir -pv /data/mysql
3、预编译及编译安装
cd /opt/mysql-5.7.18/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock-DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BOOST=/opt/mysql-5.7.18/boost/boost_1_59_0 -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make -j4
make install
4、设置启动脚本,开机自启动
chown -R mysql:mysql /usr/local/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
ln -s /usr/local/mysql/bin/* /usr/local/bin/
chkconfig --add mysqld
chkconfig mysqld on
5./etc目录下创建文件my.cnf,将下面的拷贝进去
[client]
port=3306
default-character-set=utf8
socket=/data/mysql/mysqld.sock
[mysqld]
basedir=/usr/local/mysql
port=3306
datadir=/data/mysql
socket=/data/mysql/mysqld.sock
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
6、拷贝my.cnf至/etc/目录下,并初始化数据库
#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
#(这一可忽略,因为这一步就他妈没产生my-default.cnf文件,所以自己创建,第五步)
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
注:初始化最后一行为root用户密码
7、启动服务
service mysqld start
#8.root管理员修改密码
#mysql -uroot -p,xxxxx
#mysql> update mysql.user set authentication_string=password('Mysql!@3') where user='root';
#mysql> FLUSH PRIVILEGES;
8.注意:尽量使用这个更改密码
若让使用ALTER USER更改密码,用下面的方法
修改当前登录用户
mysql> ALTER USER USER() IDENTIFIED BY 'GXB$yjy2016';
mysql> FLUSH PRIVILEGES;
密码更新为xxxxxx