一、下载
MySQL :: Download MySQL Community Server (Archived Versions)
下滑
二、卸载
1、查看MySQL的依赖项
dpkg --list|grep mysql
2、删除所有MySQL工作目录、客户端、软件包
sudo apt-get remove --purge mysql-server mysql-client mysql-common
3、清空MySQL的配置文件
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
4、清理残留依赖包
sudo apt-get autoremove
sudo apt-get autoclean
5、找到就的MySQL目录
find / -name mysql
rm -rf
三、安装
1、解压
tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
2、 移动到安装目录
sudo mv mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local
3、重命名
mv mysql-5.7.44-linux-glibc2.12-x86_64/ mysql/
4、创建文件夹
sudo mkdir -p /usr/local/mysql/data
sudo mkdir -p /usr/local/mysql/log
5、创建用户和组
sudo groupadd mysql
sudo useradd -r -g mysql mysql
6、配置权限
sudo chown -R mysql:mysql /usr/local/mysql
sudo chown -R mysql:mysql /usr/local/mysql/data
sudo chown -R mysql:mysql /usr/local/mysql/log
sudo chmod -R 755 /usr/local/mysql/data
sudo chmod -R 755 /usr/local/mysql/log
7、添加my.cnf文件
vim /etc/my.cnf
[mysqld] bind-address=0.0.0.0 #端口号 port=3306 user=mysql #mysql安装目录 basedir=/usr/local/mysql #数据的存放目录 datadir=/usr/local/mysql/data #mysql.sock 存放位置 socket=/tmp/mysql.sock #错误日志存放位置 log-error=/usr/local/mysql/log/mysql.err #pid 存放位置 pid-file=/usr/local/mysql/mysql.pid #character config character_set_server=utf8mb4 skip-name-resolve = 0 #skip-grant-tables #这个是因为忘记root密码加的 symbolic-links=0 #设置最大连接数 max_connections=20 #服务端使用字符集默认 character_set_server=utf8 #创建新表时默认的存储引擎 default_storage_engine=INNODB
8、初始化
#切换到对应目录
cd /usr/local/mysql/bin
#执行初始化命令,如果不是root账号,一定要加sudo
sudo ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
9、启动mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
10、查看密码
cat /usr/local/mysql/log/mysql.err
11、配置环境变量
vim ~/.bashrc
export PATH=$PATH:/usr/local/mysql/bin
source ~/.bashrc
12、设置开启自启
sudo systemctl enable mysql
四、配置
1、查看mysql监听的端口
sudo ss -tlnp | grep mysql
2、设置密码
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
或者
update user set authentication_string = PASSWORD('new_password') WHERE user = 'root' AND host = '%';
3、导出sql文件
mysqldump -uroot -ppassword --databeses database1 database2> bak.sql
mysqldump -uroot -ppassword --all-databases>bak.sql
mysqldump -uroot -ppassword datase1 >bak.sql
4、导入数据库
create database name;
use name;
source bak.sql
5、配置远程访问
update user set host='%' where user = 'root';
6、刷新
FLUSH PRIVILEGES;
五、可能的问题
1、问题1
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
创建一个符号链接,使得 libncurses.so.5 指向 libncurses.so.6:
sudo ln -s /lib/x86_64-linux-gnu/libncurses.so.6 /lib/x86_64-linux-gnu/libncurses.so.5
2、问题2
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
find / -name mysql.sock
如果能找到,就创建符号链接
标签:5.7,--,44,sudo,usr,mysql,MySQL,local From: https://blog.csdn.net/m0_64837052/article/details/145056669ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock