linux下重装、安装mysql,亲测可用

一、linux下重装、安装mysql

本文档讲解安装版本为mysql-5.7.24,对于5.7.24之后的版本,不适用此说明文档,主要原因在于之后版本的mysql配置文件的目录位置和结构有所改变,使用此说明可能会出现找不到配置文件或者配置后不生效的情况。

1、检查是否已经安装过mysql,执行命令

rpm -qa | grep mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rpm -qa | grep mysql
mysql-community-libs-compat-5.6.36-2.el5.x86_64
mysql-community-client-5.6.36-2.el5.x86_64
mysql-community-libs-5.6.36-2.el5.x86_64
mysql-community-common-5.6.36-2.el5.x86_64
mysql-5.6.36-2.el5.x86_64

2、检查是否已经安装过mysql,执行命令 XXXXX对应查出来的数据,以下截取部分操作记录

rpm -e XXXXX
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rpm -e --nodeps mysql-community-libs-compat-5.6.36-2.el5.x86_64
ysql-5.6.36-2.el5.x86_64warning: file /usr/lib64/mysql/libmysqlclient_r.so.15.0.0: remove failed: No such file or directory
warning: file /usr/lib64/mysql/libmysqlclient_r.so.15: remove failed: No such file or directory
warning: file /usr/lib64/mysql/libmysqlclient.so.15.0.0: remove failed: No such file or directory
warning: file /usr/lib64/mysql/libmysqlclient.so.15: remove failed: No such file or directory

2、再次操作检查,显示没有,否则继续删除

rpm -qa | grep mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rpm -qa | grep mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]#

3、查询相关目录或文件

find / -name mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# find / -name mysql
/var/lib/docker/overlay2/6970078b9b14b100a40fa2c9f84fc6bde895bd2d43a977d50ad7c5a4b1c21298/diff/var/lib/mysql
/var/lib/docker/overlay2/6970078b9b14b100a40fa2c9f84fc6bde895bd2d43a977d50ad7c5a4b1c21298/diff/etc/mysql
/var/lib/docker/overlay2/029e84569d785965cd3e5a6b8c262970d755d2f3690861abcd145728fc4f0f75/diff/var/lib/mysql
/var/lib/docker/overlay2/029e84569d785965cd3e5a6b8c262970d755d2f3690861abcd145728fc4f0f75/diff/etc/mysql
/home/soft/mysql
/etc/selinux/targeted/active/modules/100/mysql

4、删除相关目录或文件

rm -rf  XXXXX
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rm -rf /var/lib/docker/overlay2/6970078b9b14b100a40fa2c9f84fc6bde895bd2d43a977d50ad7c5a4b1c21298/diff/var/lib/mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rm -rf /var/lib/docker/overlay2/6970078b9b14b100a40fa2c9f84fc6bde895bd2d43a977d50ad7c5a4b1c21298/diff/etc/mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rm -rf /var/lib/docker/overlay2/029e84569d785965cd3e5a6b8c262970d755d2f3690861abcd145728fc4f0f75/diff/var/lib/mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rm -rf /var/lib/docker/overlay2/029e84569d785965cd3e5a6b8c262970d755d2f3690861abcd145728fc4f0f75/diff/etc/mysql
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# rm -rf /home/soft/mysql

5、再次检查相关目录或文件

find / -name mysql

6、检查mysql用户组和用户是否存在,如果没有,则创建。我的已存在

[root@localhost /]# cat /etc/group | grep mysql
[root@localhost /]# cat /etc/passwd |grep mysql
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
[root@localhost /]# 
[root@iZ2zegk0d8ne78y1ykn54mZ wang]# cat /etc/group | grep mysql
mysql:x:1000:
[root@iZ2zegk0d8ne78y1ykn54mZ wang]#

二、开始安装

1、准备包,会在当前文件中下载

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

2、解压包

tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

3、移动包、进入移动后的目录、修改包名称

mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/
cd /usr/local/
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql

3、更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限

chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

4、编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)例如:本文 eLaNjIV6hy<0 是密码

 cd /usr/local/mysql/bin
 ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
[root@iZ2zegk0d8ne78y1ykn54mZ mysql]# cd /usr/local/mysql/bin
[root@iZ2zegk0d8ne78y1ykn54mZ bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2024-08-05T12:41:48.386880Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-08-05T12:41:49.532948Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-08-05T12:41:49.697175Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-08-05T12:41:49.763655Z 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: 1594aa50-5328-11ef-99f4-00163e10c65e.
2024-08-05T12:41:49.766295Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-08-05T12:41:49.766975Z 1 [Note] A temporary password is generated for root@localhost: eLaNjIV6hy<0

5、编辑配置文件my.cnf

vi /etc/my.cnf

写入:

[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1

6、启动mysql,显示成功,如果失败可以先kill -9 一下mysql进程,再启动。

/usr/local/mysql/support-files/mysql.server start
[root@iZ2zegk0d8ne78y1ykn54mZ /]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL   
[root@iZ2zegk0d8ne78y1ykn54mZ /]#

三、访问mysql、重置密码、开放远程

1、访问mysql

进入文件夹: cd /usr/local/mysql/bin
进入mysql命令:mysql -u root -p
显示:Enter password: 输入刚才临时密码
设置密码命令: mysql>set password for root@localhost = password('你的密码');
[root@iZ2zegk0d8ne78y1ykn54mZ 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.24
Copyright (c) 2000, 2018, 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 for root@localhost = password('666666');
Query OK, 0 rows affected, 1 warning (0.00 sec)

2、开放远程访问

mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;

作者致謝原文链接: link

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值