https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/
xz -d mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz //先把文件解压成mysql-8.0.17-linux-glibc2.12-x86_64.tar
tar xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar //再解压mysql-8.0.17-linux-glibc2.12-x86_64.tar
mv mysql-8.0.17-linux-glibc2.12-x86_64 /export/servers/ //把文件夹移动到servers当中
mv mysql-8.0.17-linux-glibc2.12-x86_64 mysql //改名
5.1创建用户和用户组
groupadd mysql
useradd -r -g mysql mysql
5.2修改权限,目的是保证安装MySQL
目录的所有者为mysql
用户,所属组为MySQL
组
chown -R mysql .
chgrp -R mysql .
5.3初始化数据库
bin/mysqld --initialize --user=mysql --basedir=/export/servers/mysql --datadir=/export/data/mysql/data
初始化后,记录下初始化密码:
5.4生成配置文件
vim /etc/my.cnf
在my.cnf配置文件中填写一下内容:
[mysqld]
basedir = mnt/zdt/export/servers/mysql
datadir = mngt/zdt/export/data/mysql/data
socket = mnt/zdt/export/servers/mysql/mysql.sock
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-link=0
default_authentication_plugin=mysql_native_password
skip-grant-tables
[client]
socket = /export/servers/mysql/mysql.sock
如图:
5.5配置MySQL服务
cp /export/servers/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
5.6配置环境变量
打开/etc/profile文件,在最后填写以下内容
export MYSQL_HOME=/export/servers/mysql
export PATH=$PATH:$MYSQL_HOME/bin:$MYSQL_HOME/lib
source一下文件
source /etc/profile
service mysql start
此处启动要是报错,可能是进程里已经存在mysql进程,解决方法:
# 查看进程
ps -ef|grep mysqld
# 杀死进程
killall mysqld
# 再次重启
service mysql start
若此方法依然报错:
将/export/data/mysql/data下的文件清空,再初始化数据库:
bin/mysqld --initialize --user=mysql --basedir=/export/servers/mysql --datadir=/export/data/mysql/data
再次重启mysql:
service mysql start
mysql -u root -p
# 输入初始密码,登陆MySQL,在步骤5.3的截图上显示
更改密码
alter user'root'@'localhost' identified by '123456'
以后不想输入密码,可设置免密登录,即在
vim /etc/my.cnf
# 打开配置文件,在[msyqld]下添加skip-grant-tables
END
----------------------------------------------------------------
欢迎关注我的公众号!