解压
tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
移动到/usr/local/下并改名
mv mysql-5.7.36-linux-glibc2.12-x86_64/ /usr/local/mysql
创建data文件
# mkdir /usr/local/mysql/data
cd mysql路径
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
进入 bin路径
cd /usr/local/mysql/bin
复制密码
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
密码:
在local目录下编辑文件
Vi /etc/my.cnf
[mysqld]
# data文件路径
datadir=/usr/local/mysql/data
port=3306
user=mysql
character-set-server=utf8
[mysqld_safe]
# 日志文件路径
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
启动MySQL服务器
/usr/local/mysql/support-files/mysql.server start
Success就是成功cd
添加软连接,并重启mysql服务
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
mysql -u root -p
输入密码
更改密码
- SET PASSWORD = PASSWORD('123456');
- ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
- flush privileges;
将mysql加入系统变量:
vi /etc/profile
- 1
export PATH=$PATH:/usr/local/mysql/bin
- 1
完成后按ESC输入 :wq 保存退出,并输入下面的命令使配置生效:
source /etc/profile