上次教大家用yum安装mysql
https://blog.csdn.net/csdnerM/article/details/121095527,
结果还要小伙伴不知道tar包怎么安装,现在出个tar包安装的教程出来供大家参考
文章目录
- 🏢1.官网下载tar包(安装包)
- 🏣2.查看自己服务器是多少位的
- 🏥3.上传到服务器
- 🏦4.解压
- 🏪5.移动gz文件,并解压
- 🏩6.创建data目录
- 🏨7.修改my.cnf文件
- 💒8.修改启动参数
- ⛪️8.1给root用户添加权限
- 🏬8.2 修改安装路径
- 🏤9.初始化mysql
- 🌇10.启动mysql
- 🏫11.连接mysql
- 🏡12.修改密码
🏢1.官网下载tar包(安装包)
https://downloads.mysql.com/archives/community/
🏣2.查看自己服务器是多少位的
arch
所以我们选择
x86_64
版本
🏥3.上传到服务器
🏦4.解压
tar -xvf mysql-5.7.39-linux-glibc2.12-x86_64.tar
注意这里是
-xvf
,因为是tar
包,不是tar.gz
包
解压下来多了两个gz文件,中间有test的我们不用
🏪5.移动gz文件,并解压
mv mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz /opt/mysql/
解压
tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
名字太长,改一下名字
mv mysql-5.7.39-linux-glibc2.12-x86_64 mysql5.7
🏩6.创建data目录
记住data目录的路径,待会要用
/opt/mysql/mysql5.7/data
🏨7.修改my.cnf文件
这个mysql启动的时候会默认去找/etc/my.cnf
如果服务器没有改文件加上即可
复制以下内容
[client]
default-character-set=utf8
# 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=/opt/mysql/mysql5.7/data
socket=/tmp/mysql.sock
character-set-server=utf8
collation-server=utf8_general_ci
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
datadir填上面data的路径
💒8.修改启动参数
⛪️8.1给root用户添加权限
进入
/opt/mysql/mysql5.7/support-files
vim mysql.server
添加
--user=root
🏬8.2 修改安装路径
改成
🏤9.初始化mysql
进入bin目录
执行以下命令
./mysqld --initialize
查看初始化密码
cat /var/log/mysqld.log
上面的初始密码就是
w#,p;4uxhGxr
🌇10.启动mysql
sh mysql.server start
启动成功
🏫11.连接mysql
进入bin目录
./mysql -uroot -p
然后输入初始密码
登录成功!!
🏡12.修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456.com';
退出之后即可用新密码登录