CentOS7 二进制安装MySQL5.6.42
1. 检查是否有MariaDB和MySQL,如果有则卸载掉
# rpm -qa | egrep "mariadb|mysql" mariadb-server-5.5.60-1.el7_5.x86_64 mariadb-libs-5.5.60-1.el7_5.x86_64 mariadb-5.5.60-1.el7_5.x86_64 mariadb-devel-5.5.60-1.el7_5.x86_64 # rpm -e --nodeps mariadb-server-5.5.60 mariadb-libs-5.5.60 mariadb-5.5.60-1.el7_5.x86_64 mariadb-devel
# yum install autoconf -y
2. 下载MySQL5.6二进制安装包,选择(Linux-Generic)版
# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
3. 解压到/usr/local中改名,并创建软链接
# tar xf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz -C /usr/local/# mv /usr/local/mysql-5.6.42-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.42# ln -s /usr/local/mysql-5.6.42/ /usr/local/mysql # ll /usr/local/ total 4 drwxr-xr-x. 2 root root 6 Apr 11 2018 bin drwxr-xr-x. 2 root root 6 Apr 11 2018 etc drwxr-xr-x. 2 root root 6 Apr 11 2018 games drwxr-xr-x. 2 root root 6 Apr 11 2018 include drwxr-xr-x. 2 root root 6 Apr 11 2018 lib drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec lrwxrwxrwx 1 root root 24 Nov 29 19:40 mysql -> /usr/local/mysql-5.6.42/ drwxr-xr-x 13 root root 4096 Nov 29 19:39 mysql-5.6.42 drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin drwxr-xr-x. 5 root root 46 Apr 11 2018 share drwxr-xr-x. 2 root root 6 Apr 11 2018 src
4. 创建用户组和用户名
# groupadd mysql
# useradd -g mysql mysql -s /sbin/nologin
5. 修改配置文件
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# mkdir /var/lib/mysql/
# chown -R mysql.mysql /var/lib/mysql # cat /etc/my.cnf [mysql]
default-character-set=utf8 [mysqld] skip-name-resolve port = 3306 server_id = 1 log_bin = mysql-bin socket=/var/lib/mysql/mysql.sock basedir=/usr/local/mysql datadir=/usr/local/mysql/data max_connections=200 character-set-server=utf8 default-storage-engine=INNODB lower_case_table_name=1 max_allowed_packet=16M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [client] socket = /var/lib/mysql/mysql.sock
6. 进入mysql目录初始化数据
# chown mysql.mysql -R /usr/local/mysql # cd /usr/local/mysql/scripts/
# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7. 配置环境变量
# echo "MYSQL_HOME=/usr/local/mysql" >>/etc/profile # echo "PATH=$PATH:$MYSQL_HOME/bin" >> /etc/profile # source /etc/profile
8. 启动MySQL,并设置开机自启
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on # /etc/init.d/mysqld start
9. 设置数据库登录密码
# mysqladmin -uroot password '123456'
10. 登录数据库删除无用的帐号
# mysql -uroot -p'123456' mysql> delete from mysql.user where user=''; Query OK, 2 rows affected (0.00 sec) mysql> delete from mysql.user where host='::1'; Query OK, 1 row affected (0.00 sec) mysql> select user,host from mysql.user; +------+----------------------------+ | user | host | +------+----------------------------+ | root | 127.0.0.1 | | root | 192-168-7-77 | | root | localhost | +------+----------------------------+ 3 rows in set (0.00 sec)