mysql5.7.18二进制安装
下载mysqld二进制包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@master ~] # wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz --2020-03-01 20:44:21-- https: //downloads .mysql.com /archives/get/p/23/file/mysql-5 .7.18-linux-glibc2.5-x86_64. tar .gz 正在解析主机 downloads.mysql.com (downloads.mysql.com)... 137.254.60.14 正在连接 downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 302 Found 位置:https: //cdn .mysql.com /archives/mysql-5 .7 /mysql-5 .7.18-linux-glibc2.5-x86_64. tar .gz [跟随至新的 URL] --2020-03-01 20:44:28-- https: //cdn .mysql.com /archives/mysql-5 .7 /mysql-5 .7.18-linux-glibc2.5-x86_64. tar .gz 正在解析主机 cdn.mysql.com (cdn.mysql.com)... 104.75.165.42 正在连接 cdn.mysql.com (cdn.mysql.com)|104.75.165.42|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:654430368 (624M) [application /x-tar-gz ] 正在保存至: “mysql-5.7.18-linux-glibc2.5-x86_64. tar .gz” 100%[=====================================================================================================================================================>] 654,430,368 522KB /s 用时 19m 39s 2020-03-01 21:04:07 (542 KB /s ) - 已保存 “mysql-5.7.18-linux-glibc2.5-x86_64. tar .gz” [654430368 /654430368 ]) |
卸载mariadb或mysql系统自动安装的相关的包
1 | [root@master ~] # rpm -qa | grep maradb| xargs rpm -e --nodeps |
解压移动指定目录,并重名mysql
1 | [root@master ~] # mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql |
创建用户与组
1 2 | [root@master ~] # groupadd mysql [root@master ~] # useradd -r -g mysql mysql |
编写默认配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 | cat > /etc/my .cnf <<EOF [mysqld] datadir= /usr/local/mysql/data socket= /usr/local/mysql/mysql .sock symbolic-links=0 [mysqld_safe] log-error= /usr/local/mysql/logs/error .log pid- file = /usr/local/mysql/mysql .pid [client] socket= /usr/local/mysql/mysql .sock EOF |
创建数据目录,日志目录及文件,并授权修改用户属组
1 2 3 | [root@master ~] # mkdir /usr/local/mysql/{data,logs} [root@master ~] # touch /usr/local/mysql/logs/error.log [root@master ~] # chown mysql:mysql -R /usr/local/mysql |
初始化数据库
1 2 3 4 5 6 | [root@master ~] # /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2020-03-04T11:36:19.672944Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2020-03-04T11:36:24.605282Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-03-04T11:36:25.355978Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-03-04T11:36:25.413157Z 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: 615a0cd8-5e0c-11ea- 95be-000c29168707.2020-03-04T11:36:25.423186Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2020-03-04T11:36:25.433433Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. |
安全加固操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@master ~] # /usr/local/mysql/bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ Generating a 2048 bit RSA private key .........+++ ....+++ writing new private key to 'ca-key.pem' ----- Generating a 2048 bit RSA private key ........+++ ..............................+++ writing new private key to 'server-key.pem' ----- Generating a 2048 bit RSA private key .........................................................................................................................+++ ............................................................................................................................................................................................... ...........................+++writing new private key to 'client-key.pem' ----- |
拷贝启动脚本
1 | [root@master ~] # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld |
修改启动脚本路径
1 2 3 | [root@master ~] # sed -i '46c basedir=/usr/local/mysql' /etc/init.d/mysqld [root@master ~] # sed -i '47c datadir=/usr/local/mysql/data' /etc/init.d/mysqld [root@master ~] # sed -i '63c mysqld_pid_file_path=/usr/local/mysql/data/mysqld.pid' /etc/init.d/mysqld |
启动
1 2 | [root@master ~] # /etc/init.d/mysqld start Starting MySQL.. SUCCESS! |
修改密码
1 | [root@master ~] # mysql -e "use mysql;alter user 'root'@'localhost' identified by '123456';" |
登录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@master ~] # mysql -p123456 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 5 Server version: 5.7.18 MySQL Community Server (GPL) 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> exit Bye |
查看版本
1 2 3 4 5 6 7 | [root@master ~] # mysql -uroot -p123456 -e "select version()" mysql: [Warning] Using a password on the command line interface can be insecure. +-----------+ | version() | +-----------+ | 5.7.18 | +-----------+ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@master ~] # mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 MySQL Community Server (GPL) 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> exit Bye |
修改密码
1 | [root@master ~] # mysql -e "use mysql;alter user 'root'@'localhost' identified by '123456';" |
登录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@master ~] # mysql -p123456 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 5 Server version: 5.7.18 MySQL Community Server (GPL) 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> |
设置启动脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #Before=shutdown.target # 关机前操作 #User=mysql # 此用户必须存在,即为启动mysql的用户 cat > /usr/lib/systemd/system/mysqld .service <<EOF [mysqld] [Unit] Description=MySQL SourcePath= /etc/init .d /mysqld Before= shutdown .target [Service] User=mysql Type=forking ExecStart= /etc/init .d /mysqld start ExecStop= /etc/init .d /mysqld stop [Install] WantedBy=multi-user.target EOF |
重读文件
1 2 | root@master ~] # systemctl daemon-reload [root@master ~] # systemctl restart mysqld |
草都可以从石头缝隙中长出来更可况你呢
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏