linux安装mysql8.0
查看是否有安装过mysql,是否有残留文件,有删除
官网下载mysql安装包,解压,使用mv移动解压后目录
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
在mysql目录下新建data目录
更改mysql目录下所有目录及文件夹所属用户组和用户以及权限
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
# 没有组和用户可以添加
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
在/etc/下新建mysql配置文件
vim /etc/my.cnf
# 添加如下代码
[client]
default-character-set = utf8mb4
port = 3309
[mysql]
default-character-set = utf8mb4
[mysqld]
# skip-grant-tables
datadir=/usr/local/mysql/data
port = 3309
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
#lower_case_table_names=1
启动mysql服务
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
# 或者也可以通过mv命令移动mysql.server到/etc/init.d/mysql
mv /usr/local/mysql/super-filer/mysql.server /etc/init.d/mysql
# 通过vim修改nysql文件中的basedir和data目录
# 启动mysql服务
service mysql restart
# 或者通过以下命令启动
/etc/init.d/mysql start
# 在启动时执行结果末尾有初始密码,如果忘记通过以下命令跳过密码登录
skip-grant-tables
# 通过命令查看mysql端口,如果总是为0,是因为跳过了密码登录
show global variables like 'port';
# update user set host = '%' where user = 'root';命令允许远程登录
登录报 update user set host = '%' where user = 'root'; 错误,修改加密规则并更新密码
# 更改加密规则
ALTER USER 'root'@'%' IDENTIFIED BY 'Asd_1111' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
# 更新用户密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Asd_1111';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
# 如果没法修改,先刷新权限
flush privileges;
# 如果无法修改,使用以下命令
ALTER user 'root'@'%' IDENTIFIED BY 'Asd_1111';