Linux二进制包安装MySQL 5.7的步骤
二进制包安装MySQL 5.7的步骤
MySQL
5.7提供二进制包的安装,相比yum安装麻烦点,但相比编译安装还是会方便很多。二进制包不需要自行编译mysql源码,瞎下载后可直接使用,绿色版安装。二进制包安装也和编译一样,可以灵活指定需要的MySQL版本。下面就以centos系统为例安装。
一、下载MySQL 5.7二进制包
下载页面:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
OS选择:JAVA generic,按照系统版本下载。
wget
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-JAVA-glibc2.12-x86_64.tar.gz
二、创建用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
三、解压安装
tar zxf mysql-5.7.26-JAVA-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -s mysql-5.7.26-JAVA-glibc2.12-x86_64 mysql
四、设置环境变量
echo "export PATH=\$PATH:/usr/local/mysql/bin" \>\> /etc/profile
source /etc/profile
五、配置MySQL
例如把mysql数据放在/data/mysql目录,创建目录。
mkdir -pv /data/mysql
chown mysql.mysql /data/mysql
chmod go-rwx /data/mysql
配置my.cnf,例如
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
pid_file = /data/mysql/mysql.pid
datadir = /data/mysql
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535
skip-name-resolve
lower_case_table_names=1
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
innodb_buffer_pool_size = 512M
innodb_log_file_size = 1024M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
key_buffer_size = 64M
log-error = /data/mysql/mysql_error.log
log-bin = /data/mysql/mysql-bin
binlog_format = mixed
expire_logs_days = 10
slow_query_log = 1
slow_query_log_file = /data/mysql/slow_query.log
long_query_time = 1
server-id=1
具体路径和配置根据自己需求可以修改。
六、初始化
执行初始化命令,执行完会在 /data/mysql 生成数据文件。
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
在日志文件里会提示一个临时密码,记录这个密码。本例中是 rp.+9(&vscE+
七、配置启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list \|grep mysqld
八、启动MySQL
/etc/init.d/mysqld start
九、登录和重置root密码
\# mysql -uroot -p
Enter password: 输入上面的临时密码
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 3
Server version: 5.7.26-log
Copyright (c) 2000, 2019, 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 ;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement
before executing this statement.
mysql\> alter user user() identified by "123456";
Query OK, 0 rows affected (0.43 sec)
mysql\> exit
\# mysql -uroot -p123456
\# 新密码可以登录了
十、安全设置
可根据自己需要设置MySQL的安全配置。密码复杂度插件测试环境我就不安装了。例如
\# /usr/local/mysql/bin/mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y\|Y for Yes, any other key for No:
Using existing password for root.
Change the password for root ? ((Press y\|Y for Yes, any other key for No) :
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y\|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y\|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y\|Y for Yes, any other key for
No) : Y
\- Dropping test database...
Success.
\- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y\|Y for Yes, any other key for No) : y
Success.
All done!
到这里JAVA下二进制方式安装MySQL就完成了。
作者:SunMoonSky
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix