centos6.6 下安装mysql5.7

背景

没啥好说的,就是需要搭建自己的测试数据库跟研发的数据隔离开来,需要怼mysql

这个方法只适合mysql5.7

# mysql5.6的有差异

 

步骤

1. 确认线上mysql的版本

SELECT VERSION();

2. 确认安装方式,其实yum命令也可以直接安装,厉害了,但这样安装的话,配置不方便,一般不推荐,直接用tar.gz包来安装吧

3 .创建源包目录

mkdir -p /home/jwen/local/mysql-5.7.12

4. 下载源

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar

5.解压

tar xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar

 

 

6.解压mysql包

tar -xzvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz

 

7. 创建软链接

ln -s /home/jwen/local/mysql-5.7.12/mysql-5.7.12-linux-glibc2.5-x86_64 /home/jwen/local/mysql

 

8. 创建数据库目录

mkdir -p /home/jwen/local/mysql/data/

 

9.MYSQL初始化

./mysqld --initialize --user=jwen --basedir=/home/jwen/local/mysql --datadir=/home/jwen/local/mysql/data/

 

此处需要注意记录生成的临时密码,如上文:YLi>7ecpe;YP

 

10.SSL配置

./mysql_ssl_rsa_setup --datadir=/home/jwen/local/mysql/data/

 

11.修改配置文件,需要root权限

 

# cp my-default.cnf /etc/my.cnf
# cp mysql.server /etc/init.d/mysql

 

# vim /etc/init.d/mysql

修改以下内容:

 

basedir=/home/jwen/local/mysql

datadir=/home/jwen/local/mysql/data/

 

# vim /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]
port=3306
socket=/home/jwen/local/mysql/mysql.sock
#character-set-server=utf8
 
[mysqld]
 
# 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
socket=/home/jwen/local/mysql/mysql.sock
basedir=/home/jwen/local/mysql
max_allowed_packet=32M
explicit_defaults_for_timestamp=true
skip-ssl
secure-file-priv=NULL
back_log=300
max_connections=3000
max_connect_errors=100
table_open_cache=4096
external-locking=FALSE
###*** slow query parameters
long_query_time=6
slow_query_log
slow_query_log_file=/home/jwen/logs/mysql/slow.log
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 
[mysqldump]
quick
max_allowed_packet=32M
 
[mysqld_safe]
open-files-limit=8192
log-error=/home/jwen/logs/mysql/mysql_3306.err

手动创建不存在的目录

mkdir -p /home/jwen/logs/mysql

 

12.切换root用户(执行完后,退出到nemo用户)

创建目录  

mkdir -p /usr/local/mysql/bin

创建目录  

mkdir -p /usr/local/mysql/data

修改目录用户/目录组

chown -R jwen:jwen /usr/local/mysql

修改配置文件的用户与组:

chown jwen:jwen /etc/my.cnf

 

13.创建软连接

ln -s /home/jwen/local/mysql/bin/mysqld /usr/local/mysql/bin/mysqld

 

14.启动mysql

 ./mysqld_safe  --defaults-file=/etc/my.cnf --datadir=/home/jwen/local/mysql/data/ --user=mysql &

15.登录mysql

 ./mysql --user=root -p

--输入第7步生成的临时密码

 

16.修改密码

mysql> set password=password('rootP@123');

 

密码为rootP@123

 

17.修改root用户的权限

mysql> grant all privileges on *.* to root@'%' identified by 'rootP@123';
mysql> flush privileges;

 

18.验证

mysql> use mysql;
mysql> select host,user from user;

 

 

19.创建用户

insert into `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) values('%','guest','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0','mysql_native_password','*11DB58B0DD02E290377535868405F11E4CBEFF58','N','2016-05-10 10:16:27',NULL,'N');
commit;
flush privileges;
GRANT ALL PRIVILEGES ON *.* TO guest@'%' IDENTIFIED BY 'guest';
FLUSH PRIVILEGES;

这样就会有一个guest/guest的账号

 

20.  执行过程中请自己留意目录,哈哈哈 ,执行命令一般在mysql下的bin目录

 

posted @ 2017-12-15 16:00  whendream  阅读(636)  评论(0编辑  收藏  举报