centos7如何安装mysql5.7在前面一篇博客上已经记录了过程,整个过程编译下来几乎花了个吧小时。到92%的时候居然息屏注销了,虚拟机直接中断。中断了。。但是好消息是居然可以继续编译,然后编译完了,报了两个错。。。不过没啥事,不影响。
当我希望跑多个实例时,看到网上有人说,重新编译,然后prefix指定其他的安装路径,我的内心是崩溃的。这tm又几个小时?肯定不会那么傻。
遇到了不少坑,开始吧!!
当我们make install之后,这就是我们的安装目录
我们拷贝这个目录命名mysql-5.7.16_1(因为mysql的默认端口是3306),
将mysql的配置文件拷贝到目录下:
cp /opt/mysql-5.7.16_1/support-files/my-default.cnf /opt/mysql-5.7.16_1/my.cnf
[root@localhost opt]# vim mysql-5.7.16_1/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.
[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 = /opt/mysql-5.7.16_1/
datadir = /data/mysql3307/
port = 3307
# server_id = .....
##################多实例别忘了修改下面配置项#########################
socket = /tmp/mysql3307.sock
################################################
# 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
初始化数据库
/opt/mysql-5.7.16_1/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql-5.7.16_1 --datadir=/data/mysqldata3307
改端口,改数据存储目录,改安装目录貌似就没啥事了。
bin/mysqld_safe --defaults-file=/opt/mysql-5.7.16_1/my.cnf & (&表示后台守护进程方式执行)
连接 报错!!
[root@localhost mysql-5.7.16_1]# 2016-11-29T03:43:16.930189Z mysqld_safe Logging to '/data/mysqldata3307//localhost.localdomain.err'.
2016-11-29T03:43:17.173713Z mysqld_safe Starting mysqld daemon with databases from /data/mysqldata3307/
[root@localhost mysql-5.7.16_1]# bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
/tmp/mysql.sock是什么东西,一直这里报错。于是各种初始化数据库搞来搞去。过程是痛苦的。
终于找到了答案。其实最初的运行是成功的,不过我们没有找到本地访问它的方法
关键的来了
bin/mysql -u root -p -S /tmp/mysql3307.sock
mysql本地连接默认使用mysql.sock ,所以上面启动每次都
Can't connect to local MySQL server through socket '/tmp/mysql.sock'
-S /tmp/mysql3307.sock
指定使用此socket,这个是my.ini中刚刚我们所做的配置项。
通过这样指定 ,使用初始化数据库时产生的初始密码。
nice,进去了,然后修改密码,远程就可以访问了。
登陆修改root密码
# /opt/mysql-5.7.16/bin/mysql -uroot -p(连接mysql,输入初始化时生成的随机密码)
mysql>alter user 'root'@'localhost' identified by 'SHUNyou!#2017';
8、修改MySQL的root用户密码和授权用户管理某个数据库
mysql> grant all on db_fuyuan.* to dev_shunyou@'%' identified by 'dev_shunyou!@#2016';(新建用户账号和密码并授权用户来管理某个数据库)
mysql> flush privileges;
mysql> exit
mysql> \s (查看服务器状态)