实战:通用二进制格式安装 MySQL(mysql-5.7.29)-2024.4.6(测试成功)


实战:通用二进制格式安装 MySQL(mysql-5.7.29)-2024.4.6(测试成功)

image-20240406193532409

目录

[toc]

实验环境

mysql-5.7.29
centos7.6 1810

软件位置:

链接:https://pan.baidu.com/s/1Q0y9RW4dFgEnmK5Vc3SKUg?pwd=q2sj
提取码:q2sj
2024.4.6-实战:通用二进制格式安装 MySQL(mysql-5.7.29)-2024.4.6(测试成功)

image-20240407064737911

下载url

https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

image-20240406215438569

安装相关包

yum -y install libaio numactl-libs

准备用户

useradd -r -s /bin/false mysql

准备二进制程序

tar xf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local/
ln -s mysql-5.7.29-linux-glibc2.12-x86_64/ mysql
chown -R root.root /usr/local/mysql/

准备环境变量

echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh

准备配置文件

cp /etc/my.cnf{,.bak}

vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock        
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock

生成数据库文件,并提取root密码

mkdir -p /data/mysql
chown mysql:mysql /data/mysql
mysqld --initialize --user=mysql --datadir=/data/mysql 

...省略...
2019-07-04T13:03:54.258140Z 1 [Note] A temporary password is generated for
root@localhost: LufavlMka6,!  #注意生成root的初始密码

grep password /data/mysql/mysql.log
2019-12-26T13:31:30.458826Z 1 [Note] A temporary password is generated for
root@localhost: LufavlMka6,!

awk '/temporary password/{print $NF}' /data/mysql/mysql.log
LufavlMka6,!

注意:

我这里实际测试时需要手动创建/data/mysql目录的,但老师当时测试时不需要直接创建的。

准备服务脚本和启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start

修改口令

mysqladmin -uroot -p'LufavlMka6,!'   password magedu

另外,自己这里测试时是需要到mysql里去修改密码的,使用mysqladmin是无法正常修改密码的;

自己这里测试时报错了:

[root@vm-template ~]#awk '/temporary password/{print $NF}' /data/mysql/mysql.log
?Ny,T;oKg5t>
[root@vm-template ~]#

mysqladmin -uroot -p'?Ny,T;oKg5t>'   password magedu

[root@vm-template ~]#mysqladmin -uroot -p'?Ny,T;oKg5t>'   password magedu
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Your password has expired. To log in you must change it using a client that supports expired passwords.'
[root@vm-template ~]#

📌 gpt

[root@vm-template ~]#mysqladmin -uroot -p'?Ny,T;oKg5t>'   password magedu
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Your password has expired. To log in you must change it using a client that supports expired passwords.'

当MySQL用户的密码过期时,您将无法用常规方法或常规客户端更改密码,因为它们可能不支持密码过期功能。在这种情况下,您需要使用支持密码过期的客户端来重置密码。对于MySQL,通常意味着您需要直接连接到MySQL服务器并通过命令行进行操作。

请按照以下步骤操作:

  1. 使用支持密码过期的MySQL客户端登录。打开终端,并尝试:

    mysql -uroot -p
  2. 系统会提示您输入密码,这时输入您的旧密码 ?Ny,T;oKg5t>

  3. 如果MySQL版本支持,登录后您可能会被提示修改密码。如果是,请按提示操作。

  4. 如果没有自动提示,或者提示不起作用,您可以在MySQL提示符下运行以下命令来设置新密码:

    SET PASSWORD = PASSWORD('您的新密码');

    或者,若MySQL版本为5.7.6或更新,应使用以下命令:

    ALTER USER 'root'@'localhost' IDENTIFIED BY '您的新密码';
    
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'xyy520';

    请确保将 '您的新密码' 替换为您想要的新密码。

  5. 执行完上述命令后,退出MySQL:

    quit
  6. 现在您应该可以使用新密码通过mysqladmin或其他客户端工具连接到MySQL了。

如果您在这个过程中遇到任何问题,请再次检查您的MySQL服务器的版本和配置,因为不同版本可能需要略有不同的操作。

📌 再次测试(测试OK,符合预期)

[root@vm-template ~]#mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.7.29

Copyright (c) 2000, 2020, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xyy520';
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye
[root@vm-template ~]#mysql -uroot -pxyy520
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> \q
Bye
[root@vm-template ~]#

测试登录

[root@vm-template ~]#mysql -uroot -pxyy520
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> \q
Bye
[root@vm-template ~]#

安全初始化(可选)

#/usr/local/mysql/bin/mysql_secure_installation

Enter current password for root (enter for none): #默认没密码,这里直接回车


You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] #输入n(远程可以登录)

#mysql.sock 使用unix socket登录(只能在本地登录,不能远程登录);
/var/lib/mysql/mysql.sock文件

Change the root password? [Y/n] #输入y
New password: #输入密码:xyy520
Re-enter new password: 

Remove anonymous users? [Y/n] #输入y

Disallow root login remotely? [Y/n] #输入y,禁用root远程登录

Remove test database and access to it? [Y/n] #输入y

Reload privilege tables now? [Y/n] #输入y(是否加载权限)

shell一键安装

见如下位置:

次脚本测试成功,可一键部署的。

https://onedayxyy.cn/docs/mysql-install-bindary-shell-2

image-20240417093429061

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 微信二维码

x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号

《云原生架构师实战》

image-20230107215126971

🍀 个人博客站点

https://onedayxyy.cn/

🍀 语雀

https://www.yuque.com/xyy-onlyone

🍀 csdn

https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

image-20230107215149885

🍀 知乎

https://www.zhihu.com/people/foryouone

image-20230107215203185

最后

好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!


  目录