1:解压tar文件:
cd /usr/local/
tar -zxvf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.14-linux-glibc2.5-x86_64 mysql-5.7.14
2:进入mysql目录,创建mysql的用户组和用户,并对mysql目录设置用户组和用户
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd mysql -g mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
3:在mysql目录下创建data数据库文件目录
mkdir data
4:进入support-files目录,将my-default.cnf拷贝至etc目录下,并修改配置如下
cp my-default.cnf /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
user=mysql
# 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
basedir=/usr/local/mysql-5.7.14
datadir=/usr/local/mysql-5.7.14/data
tmpdir=/usr/local/mysql-5.7.14/data
socket=/usr/local/mysql-5.7.14/data/mysql.sock
log-error=/usr/local/mysql-5.7.14/data/mysql_error.log
default-storage-engine=INNODB
max_connections=600
table_open_cache=256
query_cache_size=1M
tmp_table_size=32M
thread_cache_size=8
innodb_data_home_dir=/usr/local/mysql-5.7.14/data
innodb_flush_log_at_trx_commit =1
innodb_log_buffer_size=128M
innodb_buffer_pool_size=128M
innodb_log_file_size=10M
innodb_thread_concurrency=16
innodb-autoextend-increment=1000
join_buffer_size = 128M
sort_buffer_size = 32M
read_rnd_buffer_size = 32M
max_allowed_packet = 32M
explicit_defaults_for_timestamp=true
sql-mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
5:安装mysql,进入bin目录运行命令:
./mysqld --user mysql --basedir=/usr/local/mysql-5.7.14 --datadir=/usr/local/mysql-5.7.14/data
./mysql_install_db --user mysql --basedir=/usr/local/mysql-5.7.14 --datadir=/usr/local/mysql-5.7.14/data
6:进入support-files目录,启动mysql服务
./mysql.server start
7:修改mysql初始密码,mysql初始密码在root目录下。查看密码:
cat /root/.mysql_secret
特别注意:仔细看清楚字母O的大小写、O与0。否则一直输入密码不对!
8:输入密码后错误信息如下:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
因为在之前的my.cnf下配置了sock文件的地址,则需建立指定地址到/tmp/mysql.sock
ln -s /usr/local/mysql-5.7.14/data/mysql.sock /tmp/mysql.sock
9:登录成功之后,修改初始密码、修改允许远程连接: