MySQL【6】——非root安装MySQL

介绍非root用户如何安装MySQL。

1. 下载

在该网址上选择对应的MySQL Community Server版本:https://dev.mysql.com/downloads/mysql/5.7.html,我这里选的是5.7.44

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.44-linux-glibc2.12-x86_64 mysql # 更改名称

创建一个my.conf文件:

[client]   
port=3336  
socket=/your_path/mysql/mysql.sock  

[mysqld]
port=3336
basedir=/your_path/mysql
datadir=/your_path/mysql/data
pid-file=/your_path/mysql/mysql.pid
socket=/your_path/mysql/mysql.sock
log_error=/your_path/mysql/error.log
server-id=100

在mysql目录下运行:

bin/mysqld --defaults-file=/your_path/mysql/my.cnf --basedir=/your_path/mysql/ --datadir=/your_path/mysql/data/ --user=mysql --initialize 

找error.log里面的初始密码:

cat error.log

A temporary password is generated for root@localhost: YkGFpqMki7?<

启动:

bin/mysqld_safe \
--defaults-file=/your_path/mysql/my.cnf \
--user=oper &

增加sock路径:

bin/mysql -u root -p -S /your_path/mysql/mysql.sock

输入初始密码即可登陆。

参考资料:

comments powered by Disqus