赞
踩
rpm -qa | grep mysql
# 这里的XXXXXX表示依赖名
rpm -e XXXXXX --nodeps
find / -name mysql
rm -rf /var/lib/selinux/targeted/active/modules/100/mysql
tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql8
useradd mysql
passwd mysql
chown -R mysql:mysql /usr/local/mysql8
vim /etc/my.cnf
# 优先读取/etc/my.cnf.d目录下配置文件,一般用不着
#!includedir /etc/my.cnf.d
# 客服端设置
[client]
# 服务套接字位置
socket=/mnt/data/mysql/mysql.sock
[mysqld]
# 数据目录,路径的位置根据实际情况配置,给目录指定权限,否真会报权限问题
datadir=/mnt/data/mysql/mysql-data
# mysql端口号
port = 3306
# 日志文件输出,需要给目录配置权限,否则会报目录权限问题
log-error=/mnt/data/mysql/mysql-logs/mysql.log
# 不区分大小写
# MySQL在Windows上会将所有的表名和数据库名转换为小写,并且在查询时不区分大小写。这有助于在不同操作系统之间移植数据库
lower_case_table_names=1
# 服务套接字位置,需要给目录配置权限
socket=/mnt/data/mysql/mysql.sock
# 是否与旧版本的客户端兼容,可能需要将此参数设置为mysql_native_password
# default_authentication_plugin=mysql_native_password
# 最大传输如果数据包超过这个大小,MySQL会报错
# max_allowed_packet=64M
# 最大连接并发数据量
# max_connections=1000
chown -R mysql:mysql /mnt/data/mysql/mysql-data
chown -R 755 /mnt/data/mysql/mysql-data
chown -R mysql:mysql /mnt/data/mysql/mysql-logs
chmod -R 755 /mnt/data/mysql/mysql-logs
chown -R mysql:mysql /mnt/data/mysql
chown -R 755 /mnt/data/mysql
chmod -R 777 /mnt/data/mysql/
mkdir -p /mnt/data/mysql/mysql-data
mkdir -p /mnt/data/mysql/mysql-logs
ln -snf /usr/local/mysql8/bin/mysql /usr/bin/mysql
ln -snf /usr/local/mysql8/bin/mysqld /usr/sbin/mysqld
ln -snf /usr/local/mysql8/bin/mysqladmin /usr/bin/mysqladmin
ln -snf /usr/local/mysql8/bin/mysqlbinlog /usr/bin/mysqlbinlog
ln -snf /usr/local/mysql8/bin/mysqlcheck /usr/bin/mysqlcheck
ln -snf /usr/local/mysql8/bin/mysql_config_editor /usr/bin/mysql_config_editor
ln -snf /usr/local/mysql8/bin/mysqldump /usr/bin/mysqldump
ln -snf /usr/local/mysql8/bin/mysqldumpslow /usr/bin/mysqldumpslow
ln -snf /usr/local/mysql8/bin/mysqlimport /usr/bin/mysqlimport
ln -snf /usr/local/mysql8/bin/mysqlpump /usr/bin/mysqlpump
ln -snf /usr/local/mysql8/bin/mysql_secure_installation /usr/bin/mysql_secure_installation
ln -snf /usr/local/mysql8/bin/mysqlshow /usr/bin/mysqlshow
ln -snf /usr/local/mysql8/bin/mysqlslap /usr/bin/mysqlslap
ln -snf /usr/local/mysql8/bin/mysql_tzinfo_to_sql /usr/bin/mysql_tzinfo_to_sql
ln -snf /usr/local/mysql8/bin/mysql_upgrade /usr/bin/mysql_upgrade
mysql -V
mysqld -V
export PATH=$PATH:/usr/local/mysql8/bin
vim /etc/profile
export PATH=$PATH:/usr/local/mysql8/bin
cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
basedir=/usr/local/mysql8 (mysql的安装路径)
datadir=/mnt/data/mysql/mysql-data (这里要与配置文件保持一致)
cp /etc/init.d/mysqld /etc/init.d/mysql
chkconfig --add mysqld
systemctl daemon-reload
chkconfig --list
mysqld --user=mysql --basedir=/usr/local/mysql8 --initialize
初始化后,查看mysqld.log(默认/var/log/mysqld.log或本文取决于my.cnf的日志路径配置),找到root初始密码,在执行上方initialize语句时mysqld.log文件中就会打印,如图所示:
启动mysql:
service mysqld start
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
出错原因:
using password: NO
:表示输入没有输入密码就尝试登陆了
using password: YES
:表示输入了密码,但密码错误
这里表示很有可能是忘记密码了,或者初始化的时候,初始化密码不生效,因此需要重设密码。
找到 MySQL 的配置文件 “my.ini”,如果自己配置了配置文件,就到自己配置的配置文件里面找,比如我们当前文档2.4处配置的文件地址为/etc/my.cnf
,vim配置文件后,找到 [mysqld],在其下面任意一行添加 skip-grant-tables,保存,如下图所示:
service mysqld restart
mysql -uroot -p
use mysql;
update user set authentication_string='' where user='root';
quit;
service mysqld restart
mysql -uroot -p
flush privileges;
后回车ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
后回车# 刷新权限
flush privileges;
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
解决办法
mysql> SET PASSWORD = PASSWORD('Admin2022!');
mysql> ALTER USER USER() IDENTIFIED BY 'Admin2022!';
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。