一.准备环境
1. 官网下载mysql 5.6.38
https://dev.mysql.com/downloads/mysql/5.6.html#downloads
2. 卸载旧版mysql
查询安装包
[root@centos1~]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-7.el6.x86_64
mysql-server-5.1.73-7.el6.x86_64
删除安装包
[root@centos1~]# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
[root@centos1~]# rpm -e --nodeps mysql-server-5.1.73-7.el6.x86_64
查找mysql安装目录
[root@centos1~]# find / -name mysql
/usr/share/mysql
/usr/include/mysql
/usr/bin/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
删除安装目录
[root@centos1~]# rm -rf /var/lib/mysql/
...
(删除完所有查询出来的目录)
删除my.cnf
[root@centos1~]# rm -rf /etc/my.cnf
删除用户
[root@centos1 ~]# userdel -r mysql
二. 安装mysql
1. 创建用户
[root@centos1~]# groupadd mysql
[root@centos1~]# useradd -r -g mysql mysql
2.解压软件
解压
[root@centos1 local]# tar -zxvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
重命名
[root@centos1 local]# mv mysql-5.6.38-linux-glibc2.12-x86_64 mysql
删除已安装压缩文件
[root@centos1 local]# rm mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
3. 修改权限
[root@centos1 local]#chown -R mysql:mysql mysql/
4.初始化数据库
[root@centos1 local]# cd /usr/local/mysql/scripts
[root@centos1 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
注意:这里可能会有以下提示
[root@bogon mysql]
# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
FATAL ERROR: please
install
the following Perl modules before executing .
/scripts/mysql_install_db
:Data::Dumper
下载地址:https://pkgs.org/download/perl(Data::Dumper)
安装插件
[root@centos1 local]# cd /home
[root@centos1 home]# rpm -ivh perl-Data-Dumper-2.145-3.el7.x86_64.rpm
再初始化数据库
[root@centos1 home]# cd /usr/local/mysql/scripts
[root@centos1 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
5.配置文件my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
port = 3306
socket= /tmp/mysql.sock
[mysql]
prompt="\\u@\\h [\\d]>"
no-auto-rehash
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
event_scheduler = 0
tmpdir = /usr/local/mysql/tmp
#timeout
interactive_timeout = 300
wait_timeout = 300
#character set
character-set-server = utf8
open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
lower_case_table_names =1
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
注意:需要在mysql目录下创建tmp临时目录,因为my.conf配置的文件中配置了
[root@centos1 mysql]# mkdir tmp
6.配置环境变量
[root@centos1 local]# vi ~/.bashrc
export MYSQL_HOME= /usr/local/mysql
export PATH=$PATH:MYSQL_HOME/bin
7.启动测试
[root@centos1 local]# service mysql start
Starting MySQL. SUCCESS!
8.修改默认密码
[root@centos1 local]#mysqladmin -uroot -p password "newPassword"
注意:如果忘记密码,停掉mysql服务,用不进行权限验证的启动方式启动,所有登录将不验证密码
[root@centos1 local]#mysqld_safe --skip-grant-tables &
9.修改远程可访问
登录mysql后执行更新语句
update user set host='%' where user='root';
最后恭喜你安装完成!