centos7 mysql5.7离线安装

1.下载mysql

https://pan.baidu.com/s/1Dld4cpo2h_dECTMusMLfUg   提取码:lmkh

2.查看并删除机器中 mariadb


rpm -qa | grep mariadb
rpm -qa | grep mariadb |xargs yum remove -y

3.查找并删除mysql残留文件

find / -name mysql

rm -rf /var/lib/mysql
rm -rf /var/log/mysqld.log
rm -rf /var/log/mysql.log

4. mysql-5.7.30-1.el7.x86_64.rpm.tar上传解压

tar -xvf mysql-5.7.30-1.el7.x86_64.rpm.tar

5.依次安装解压后的RPM包(注:必须按顺序依次安装,否则会因缺少依赖安装失败)

rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm

6.修改mysql配置文件 ,根据自己需求 编辑 /etc/my.cnf 文件 

ps 注意自定义存储路径和日志路径,要更改自定义目录的所属用户和读写权限

# 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=/data/mysql/data
socket=/data/mysql/data/mysql.sock

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

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

[client]
port=3306
socket=/data/mysql/data/mysql.sock
chown -R mysql:mysql /data/mysql
chmod -R 777 /data/mysql

7.修改mysql配置后,如果更改mysql数据的默认存储地址,需要重新初始化更改后的目录

mysqld  --initialize

8.启动mysql

systemctl start mysqld.service

9 查看mysql运行状态

systemctl status mysqld

10 查看mysql启动日志,获得root用户的默认密码

tail -f -n 200 /data/mysql/log/mysqld.log
2022-09-21T02:00:26.402396Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option
 (see documentation for more details).
2022-09-21T02:00:26.620666Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-09-21T02:00:26.658043Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-09-21T02:00:26.715686Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Ge
nerating a new UUID: 29588cde-3951-11ed-8d10-286ed48993c2.
2022-09-21T02:00:26.717087Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-09-21T02:00:27.410586Z 0 [Warning] CA certificate ca.pem is self signed.
2022-09-21T02:00:27.742405Z 1 [Note] A temporary password is generated for root@localhost: xxxxxxxxx

11.设置Mysql 开机自启动

sudo systemctl enable mysqld

12 从日志文件中查询root用户默认密码,连接mysql,第一次连接需要更改root用户密码。

grep 'temporary password' /data/mysql/log/mysqld.log
mysql -u root -p
alter user root@localhost identified by 'xxxxxxxxxxxxx';

13 开启mysql允许远程访问,连到mysql后执行

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 
mysql> 
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> 
mysql> 
mysql> 
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

你可能感兴趣的:(笔记,centos,linux,运维,mysql,数据库)