MySql教程

Mysql8.0安装

本文主要是介绍Mysql8.0安装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Mysql安装

安装:忘记咋安装了,反正安装的版本是8.0.25
出现了以下问题 mark一下:

  1. 启动失败,先去确认启动失败,查看端口起来没:
lsof -i 3306
  1. 如果没有,则查看mysql的状态:
service mysqld status
  1. 当发现启动失败,即出现failed to start mysql的文段,
  2. 先重启看看:
systemctl restart mysqld.service
  1. 执行journalctl -xe查看文档。报错:
Failed to start MySQL Server.
Unit mysqld.service entered failed state.
  1. 根据博客 :
# 修改/etc/my.cnf的datadir配置项
# 默认的是:

datadir=/var/lib/mysql
# 在 /var/lib/mysql创建个data目录 datadir改成
datadir=/var/lib/mysql/data
  1. 再次登录发现,不记得密码,具体现象如下:
[root@VM-4-17-centos etc]# sudo mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@VM-4-17-centos etc]# sudo mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@VM-4-17-centos etc]# sudo mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@VM-4-17-centos etc]# sudo mysql 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@VM-4-17-centos etc]# mysqld -console --skip-grant-tables --shared-memory
2022-03-24T16:21:51.399204Z 0 [System] [MY-010116] [Server] /usr/local/mysql-8.0/bin/mysqld (mysqld 8.0.25) starting as process 24925
2022-03-24T16:21:51.402833Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2022-03-24T16:21:51.402893Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-03-24T16:21:51.403171Z 0 [System] [MY-010910] [Server] /usr/local/mysql-8.0/bin/mysqld: Shutdown complete (mysqld 8.0.25)  MySQL Community Server - GPL.
[root@VM-4-17-centos etc]# mysqld 
2022-03-24T16:22:05.531085Z 0 [System] [MY-010116] [Server] /usr/local/mysql-8.0/bin/mysqld (mysqld 8.0.25) starting as process 24975
2022-03-24T16:22:05.534526Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2022-03-24T16:22:05.534577Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-03-24T16:22:05.534798Z 0 [System] [MY-010910] [Server] /usr/local/mysql-8.0/bin/mysqld: Shutdown complete (mysqld 8.0.25)  MySQL Community Server - GPL.
[root@VM-4-17-centos etc]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

再看发现Mysql8.0默认生成随机密码,然后你进去需要修改密码,先去日志找密码:

find / -name mysqld.log
cd /var/log/
cat mysqld.log 

根据密码登陆,然后修改密码:

# ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
alter user user() identified by '123456';
# ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
alter user user() identified by '?????';

修改密码完成。 成功可以登陆

其他问题

由于Mysql在有时会出现mysql.sock定位误差,会造成不连接数据库。
mac由当时的误差:
第一个变化my.cnf
位置/etc/my.cnf下一个,如果没有,那么。跟/usr/locate/mysql号/my.cnf下改动,然后拷贝到/etc下。
改动为例如以下:

[client]
socket = /tmp/mysql.sock
[mysqld]
socket = /tmp/mysql.sock

没有[client]的话。自己加入~

这篇关于Mysql8.0安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!