1、登录官网下载社区版,本例是5.7.18版本
2、选择Linux系统rpm安装包,主要包括如下四个文件
mysql-community-common-5.7.19-1.el6.x86_64.rpm
mysql-community-libs-5.7.19-1.el6.x86_64.rpm
mysql-community-client-5.7.19-1.el6.x86_64.rpm
mysql-community-server-5.7.19-1.el6.x86_64.rpm
3、安装
root用户下登录
[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-common-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-client-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
这步多容易报错,主要是rpm依赖包的问题,根据提示安装依赖的包即可,一步步进行。
4、配置/etc/my.cnf
[mysqld]
port=3336
datadir=/data/mysql/data
socket=/data/mysql/data/mysql.sock
user=mysql
event_scheduler = 1
lower_case_table_names=1
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
port=3336
socket=/data/mysql/data/mysql.sock
此步中文件路径根据需要修改,后面步骤中出现的目录根据需求修改
存储初始的datadir目录务必保证充足的空间
5、更改mysql数据库目录的所属用户及其所属组
chown mysql:mysql /var/lib/mysql -R
chown mysql:mysql /data/mysql -R
6、初始化
[root@localhost mysql]# mysqld --user=mysql --datadir=/data/mysql/data --initialize
2018-01-03T09:24:23.682590Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-01-03T09:24:24.666138Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-01-03T09:24:24.798230Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-01-03T09:24:24.859663Z 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: e3953fd5-f067-11e7-ac4d-005056852b5f.
2018-01-03T09:24:24.863370Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-01-03T09:24:24.864464Z 1 [Note] A temporary password is generated for root@localhost: E)a*ryw2*rha
记住最后的初始密码,后面要用的着
7、启动
[root@localhost bin]# service mysqld start
Starting mysqld: [ OK ]
[root@localhost bin]# service mysqld status
mysqld (pid 22491) is running...
[root@localhost bin]# ps -ef|grep mysql
root 22270 1 0 17:34 pts/5 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/data/mysql/data --socket=/data/mysql/data/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 22491 22270 3 17:34 pts/5 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/data/mysql/data --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/data/mysql/data/mysql.sock --port=3306
root 22813 3058 0 17:34 pts/5 00:00:00 grep mysql
8、修改root密码
[root@localhost bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>SET PASSWORD = PASSWORD('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
9、添加远程访问权限
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host, user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> exit;
10、重启生效
service mysqld restart
补充
rmp卸载
rpm -qa|grep mysql
rpm -e mysql-community-server-5.7.19-1.el6.x86_64,按安装的反序依次卸载
whereis mysql 和 find / -name mysql
rm -f xxx
安装时常见报错处理
报错处理1
[root@localhost aiuap_cj]# rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
warning: mysql-community-libs-5.7.19-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.19-1.el6.x86_64
查看发现系统中存在lib包,清除yum中所有依赖包再进行安装,ok
[root@localhost aiuap_cj]# rpm -qa|grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[root@localhost aiuap_cj]# yum remove mysql-libs
报错处理2
[root@localhost soft]# rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm
警告:mysql-community-server-5.7.19-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
libsasl2.so.2()(64bit) 被 mysql-community-server-5.7.19-1.el6.x86_64 需要
强制进行安装
[root@localhost soft]# rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm --force --nodeps
警告:mysql-community-server-5.7.19-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.19-1.e################################# [100%]
报错3
[ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
目录权限问题,如果赋权后还无法解决,可关闭SELinux,setenforce 0
本文档介绍了如何在Linux系统中通过rpm方式安装MySQL 5.7.19,包括下载安装包、解决依赖问题、配置my.cnf、初始化数据库、设置root密码、授权远程访问及卸载MySQL的详细步骤。在安装过程中可能会遇到的错误及解决办法也进行了说明。

2005

被折叠的 条评论
为什么被折叠?



