mysql5.7的安装

一、浩语

时间,不一定能证明许多东西,但一定会看透许多东西。越来越觉得,照顾好自己,不给别人添麻烦,是成长重要的一步。

二、背景

最近离职交接,在折腾disconf所以就需要安装mysql,因此就引出了安装问题,记载一下。

三、安装

先下载包

 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gzhttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
Paste_Image.png
[mbr@localhost bin]$ ./mysql_install_db --user=mbr --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2017-03-22 14:06:12 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-03-22 14:06:12 [ERROR]   The data directory '/usr/local/mysql/data' already exist and is not empty.
[mbr@localhost bin]$ ./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize

清空data目录


hah
[mbr@localhost bin]$ ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2017-03-22T06:10:27.796422Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-03-22T06:10:27.796508Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-03-22T06:10:27.796741Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-22T06:10:27.799052Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2017-03-22T06:10:27.799081Z 0 [ERROR] Aborting

使用mysql的用户


Paste_Image.png
[mbr@localhost bin]$ ./mysqld --user=mbr --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2017-03-22T06:10:04.037209Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-03-22T06:10:04.037282Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-03-22T06:10:04.037435Z 0 [Warning] Ignoring user change to 'mbr' because the user was set to 'mysql' earlier on the command line

2017-03-22T06:10:04.037452Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-22T06:10:04.039674Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2017-03-22T06:10:04.039704Z 0 [ERROR] Aborting
Paste_Image.png
[mbr@localhost bin]$ ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2017-03-22T06:13:51.307390Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-03-22T06:13:51.307479Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-03-22T06:13:51.307697Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-22T06:13:51.310657Z 0 [Warning] One can only use the --user switch if running as root

2017-03-22T06:14:32.306149Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-03-22T06:14:33.132151Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-03-22T06:14:33.275111Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d11d2492-0ec6-11e7-a271-005056be25e7.
2017-03-22T06:14:33.294768Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-03-22T06:14:33.295656Z 1 [Note] A temporary password is generated for root@localhost: lHsaS#S&.2(s
[mbr@localhost bin]$ ../support-files/mysql.server start
Starting MySQL./usr/local/mysql/bin/mysqld_safe: line 586: /var/lib/mysql/mysqld_safe.pid: 没有那个文件或目录
awk: (FILENAME=- FNR=1) 警告: 向标准输出写时发生错误 (断开的管道)
/usr/local/mysql/bin/mysqld_safe: line 139: /var/log/mysqld.log: 权限不够
2017-03-22T07:10:08.030812Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
/usr/local/mysql/bin/mysqld_safe: line 139: /var/log/mysqld.log: 权限不够
The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).[失败]

解决方式:

cp /usr/local/mysql/support-files/my-default.cnf    /usr/local/mysql/support-files/my.cnf 
 cp /usr/local/mysql/support-files/my.cnf  /etc/

将这个复制到/etc/目录下就行,启动结果如下

Paste_Image.png
Paste_Image.png

授权出现问题

 You must reset your password using ALTER USER statement before executing this statement.

解决如下:


grant_Image.png

编辑

vim /etc/my.cnf
在[mysqld]下加入skip-grant-tablesshan用来跳过密码
[mysqld]
skip-grant-tablesshan

重启mysql

/usr/local/mysql/support-files/mysql.server stop
/usr/local/mysql/support-files/mysql.server start
mysql -uroot -p
###进入后
user mysql;
update user set authentication_string=PASSWORD("123456")  where user='root' and host='localhost'

上面图片中grant_image的图片中,由于授权的提示,所以才又

set PASSWORD = PASSWORD('123456');

每次执行了授权操作后都需要flush privileges刷新下。

我的安装借鉴了<a href="http://www.cnblogs.com/gaojupeng/p/5727069.html">这篇文章</a>

只是在修改不了密码的时候我使用跳过密码的方式来解决,因为文章里面的方式还是解决不了我登录不上的问题。

配置启动

 cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld  
chmod 755  /etc/init.d/mysqld   ###增加执行权限
chkconfig --list mysqld             ###检查启动列表是否已经有了mysqld
chkconfig --add mysqld          ###添加进去
chkconfig mysqld on              ###设置开机启动
Paste_Image.png

然后就可以使用如下命令进行启动停止等操作

service mysqld start
service mysqld restart
service mysqld stop

然后创建软连接,这样就可以直接在命令行里面使用mysql的命令比如如下图片中的登录mysql -uroot -p

 ln -s /usr/local/mysql/bin/mysql  /usr/bin/mysql
Paste_Image.png

其实这里创建软连接是一种方式,其实也可以配置全局变量的方式来.我自己的mac电脑上市这样配置的。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容