当前位置: 代码网 > it编程>数据库>Mysql > CentOS Linux 7系统中离线安装MySQL5.7步骤

CentOS Linux 7系统中离线安装MySQL5.7步骤

2024年08月06日 Mysql 我要评论
rw-r--r-- 1 root root 570705920 6月 20 13:45 mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar [root@hadoop54 temp]#警告:mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY。警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave。

预计数据文件存储目录为:/opt/mysql/data

1、文件下载:

安装文件下载链接:https://downloads.mysql.com/archives/community/

2、检查当前系统是否安装过mysql

[root@cnic51 mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@cnic51 mysql]# sudo rpm -e --nodeps mariadb-libs
警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave
[root@cnic51 mysql]# rpm -qa|grep mariadb
[root@cnic51 mysql]#

3、将mysql安装包拷贝到linux服务器的/opt/temp/目录下

[root@hadoop54 temp]# ll
总用量 570706
-rw-r--r-- 1 root root  570705920 6月  20 13:45 mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar [root@hadoop54 temp]#

4、解压mysql安装包

[root@cnic51 temp]# tar -xvf mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.44-1.el7.x86_64.rpm
mysql-community-common-5.7.44-1.el7.x86_64.rpm
mysql-community-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-server-5.7.44-1.el7.x86_64.rpm
mysql-community-test-5.7.44-1.el7.x86_64.rpm
[root@cnic51 temp]#

5、在安装目录下执行rpm安装,按顺序安装

[root@cnic51 temp]# sudo rpm -ivh mysql-community-common-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.44-1.e################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-libs-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.44-1.el7################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-compat-5.7.4################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-client-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.44-1.e################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-server-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.44-1.e################################# [100%]
[root@cnic51 temp]#

6、修改/etc/my.cnf文件中datadir指向的目录下的所有内容,如果有内容的情况下:
查看datadir的值,将其修改为如下:

旧的内容为:

# for advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[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
#
# 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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

新的内容为:

# for advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[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
#
# 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
skip-name-resolve
basedir=/opt/mysql
datadir=/opt/mysql/data
max_connections=2000
port=3306
character-set-server=utf8
default-storage-engine=innodb
lower_case_table_names=1
max_allowed_packet=16m
explicit_defaults_for_timestamp=true
sql_mode=strict_trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_auto_create_user,no_engine_substitution
socket=/var/lib/mysql/mysql.sock

# disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/opt/mysql/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

删除/var/lib/mysql目录下的所有内容(如果指定的目录不是默认的可以不用管):
[root@hadoop54 mysql]# cd /var/lib/mysql
[root@hadoop54 mysql]# ls
[root@hadoop54 mysql]# sudo rm -rf *
[root@hadoop54 mysql]#

7、初始化数据库

[root@hadoop51 mysql]# sudo chown -r mysql:mysql /opt /mysql
[root@hadoop51 mysql]# sudo mysqld --initialize --user=mysql
[root@hadoop51 mysql]#

8、查看临时生成的root帐号密码
2024-06-20t06:17:53.912194z 0 [error] can't find error-message file '/opt/mysql/share/mysql/errmsg.sys'. check error-message file location and 'lc-messages-dir' configuration directive.
2024-06-20t06:17:54.145587z 0 [warning] innodb: new log files created, lsn=45790
2024-06-20t06:17:54.220326z 0 [warning] innodb: creating foreign key constraint system tables.
2024-06-20t06:17:54.287423z 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: d45d6ffd-2ecc-11ef-a74a-fa081328b000.
2024-06-20t06:17:54.295842z 0 [warning] gtid table is not ready to be used. table 'mysql.gtid_executed' cannot be opened.
2024-06-20t06:17:55.180876z 0 [warning]
2024-06-20t06:17:55.180891z 0 [warning]
2024-06-20t06:17:55.184006z 0 [warning] ca certificate ca.pem is self signed.
2024-06-20t06:17:55.315891z 1 [note] a temporary password is generated for root@localhost: 8<a.-mrijeif

9、启动mysql数据库
[root@hadoop51 mysql]#  sudo systemctl start mysqld

10、登录mysql数据库

[root@cnic51 mysql]# mysql -uroot -p
enter password:
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 2
server version: 5.7.44

copyright (c) 2000, 2023, oracle and/or its affiliates.

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("123456");
query ok, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
query ok, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'dev'@'%' identified by '123456' with grant option;
query ok, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to 'dev'@'localhost' identified by '123456' with grant option;
query ok, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)

mysql>

必须先修改root用户的密码,否则执行其他的操作会报错
mysql> set password = password("123456");
query ok, 0 rows affected, 1 warning (0.00 sec)

11、根据需要是否修改mysql库下的user表中的root用户允许任意ip连接
mysql> update mysql.user set host='%' where user='root';
query ok, 1 row affected (0.00 sec)
rows matched: 1  changed: 1  warnings: 0

mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)

新建账号及授权语句:
mysql> grant all privileges on *.* to 'dev'@'%' identified by '123456' with grant option;
query ok, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to 'dev'@'localhost' identified by '123456' with grant option;
query ok, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com