【介绍】
参考:https://blog.csdn.net/wm609972715/article/details/83759266
【安装】
下载:https://dev.mysql.com/downloads/repo/apt/
wget https://dev.mysql.com/get/mysql-apt-config_0.8.14-1_all.deb sudo dpkg -i mysql-apt-config_0.8.14-1_all.deb
选择MySQL-8.0 ,点击OK继续安装
执行更新命令:
sudo apt update
安装MySQL 8.0,执行命令:
sudo apt install mysql-server
运行mysql_secure_installation脚本,设置MySQL根密码并执行一些与安全性相关的操作:
sudo mysql_secure_installation
MySQL8.0默认已经是utf8mb4字符集,所以字符集不再修改。
MySQL8.0采用了新的加密方式,与Ubuntu18.04有兼容问题;故选择下面的 Retain MySQL 5.x Compatibility
登录 MySQL :
mysql -u root -p
查看MySQL字符集,MySQL-8.0字符集默认为UTF-8,执行命令:
show variables like '%char%';
【命令】
命令:
service mysql start service mysql restart service mysql stop
【配置】
寻找配置文件路径:
mysqladmin --help
输出:
... Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf ...
配置文件路径:
/etc/mysql/
搜索 my.cnf 文件:
find / -name my.cnf
输出:
/etc/mysql/my.cnf /etc/alternatives/my.cnf /var/lib/dpkg/alternatives/my.cnf
搜索 mysql 文件:
find / -name mysql
输出:
/usr/share/php8.1-mysql/mysql /usr/share/mysql /usr/share/bash-completion/completions/mysql /usr/bin/mysql /usr/lib/mysql /etc/mysql /etc/init.d/mysql /etc/apparmor.d/abstractions/mysql /var/log/mysql /var/lib/mysql /var/lib/mysql/mysql
【卸载】
删除 MySQL:
apt-get autoremove mysql-server
清理残留数据:
dpkg -l |grep ^rc|awk '{print $2}' |xargs dpkg -P
【排错】
报错:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
当在命令行使用密码 进入 MySQL 时报此错误。
参考:https://blog.csdn.net/hjf161105/article/details/78850658
参考:https://www.jianshu.com/p/f9c044747133
... [client] socket=/var/run/mysqld/mysqld.sock ... [mysqld] socket=/var/run/mysqld/mysqld.sock ...
设置权限:
chmod 777 /var/run/mysql
使用密码 进入 MySQL 命令行;
mysql -u root -p -S /var/run/mysqld/mysqld.sock
分析:是否因为版本升级导致 mysql.sock 变更为 mysqld.sock ?
报错:mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
因为在MySQL 8.0.11中,caching_sha2_password 是默认的身份验证插件,而不是以往的mysql_native_password。所以和php不兼容。可以降级php,也可以修改MySQL的配置。
修改MySQL的配置:/etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld] port=3306 character-set-server=utf8 default_authentication_plugin=mysql_native_password [mysql] default-character-set=utf8 [client] default-character-set=utf8