上次教大家用yum安装mysql
https://blog.csdn.net/csdnerM/article/details/121095527,
结果还要小伙伴不知道tar包怎么安装,现在出个tar包安装的教程出来供大家参考
https://downloads.mysql.com/archives/community/
arch
所以我们选择
x86_64
版本
tar -xvf mysql-5.7.39-linux-glibc2.12-x86_64.tar
注意这里是
-xvf
,因为是tar
包,不是tar.gz
包
解压下来多了两个gz文件,中间有test的我们不用
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
记住data目录的路径,待会要用
/opt/mysql/mysql5.7/data
这个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的路径
进入
/opt/mysql/mysql5.7/support-files
vim mysql.server
添加
--user=root
进入bin目录
执行以下命令
./mysqld --initialize
查看初始化密码
cat /var/log/mysqld.log
上面的初始密码就是
w#,p;4uxhGxr
sh mysql.server start
启动成功
进入bin目录
./mysql -uroot -p
然后输入初始密码
登录成功!!
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456.com';
退出之后即可用新密码登录