[root@localhost ~]# cat /proc/version
Linux version 5.15.0-89-generic (buildd@bos03-amd64-016) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023
[root@localhost ~]#
[root@localhost ~]# getconf LONG_BIT
64
https://dev.mysql.com/downloads/mysql/
https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-server_8.2.0-1ubuntu22.04_amd64.deb-bundle.tar
# 下载
wget https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-server_8.2.0-1ubuntu22.04_amd64.deb-bundle.tar
# 解压
tar xvf mysql-server_8.2.0-1ubuntu22.04_amd64.deb-bundle.tar
# 安装,注意顺序
sudo dpkg -i mysql-community-client-plugins_8.2.0-1ubuntu22.04_amd64.deb
sudo dpkg -i mysql-community-client-core_8.2.0-1ubuntu22.04_amd64.deb
sudo dpkg -i mysql-common_8.2.0-1ubuntu22.04_amd64.deb
sudo dpkg -i mysql-community-client_8.2.0-1ubuntu22.04_amd64.deb
sudo dpkg -i libmysqlclient22_8.2.0-1ubuntu22.04_amd64.deb
sudo dpkg -i libmysqlclient-dev_8.2.0-1ubuntu22.04_amd64.deb
sudo dpkg -i mysql-client_8.2.0-1ubuntu22.04_amd64.deb
# 依赖包 如果解压出来没有libaio1这个包,那么直接用apt安装:apt install libaio1
sudo apt install libaio1
# 依赖包
sudo apt install libmecab2
sudo dpkg -i mysql-community-server-core_8.2.0-1ubuntu22.04_amd64.deb
# 这一步要设置root密码,默认root只能localhost连接
sudo dpkg -i mysql-community-server_8.2.0-1ubuntu22.04_amd64.deb
sudo dpkg -i mysql-server_8.2.0-1ubuntu22.04_amd64.deb
# 查看版本
mysql -V
# mysql Ver 8.2.0 for Linux on x86_64 (MySQL Community Server - GPL)
sudo service mysql stop
sudo service mysql start
sudo service mysql restart
# 或者
sudo systemctl stop mysql
sudo systemctl start mysql
sudo systemctl restart mysql
ps aux | grep mysql
# 或者
sudo service mysql status
# 或者
sudo systemctl status mysql
which mysql
/usr/bin/mysql
/usr/bin/mysql --verbose --help | grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
sudo vim /etc/mysql/my.cnf
...
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
也可以连接到mysql查看
mysql -uroot -p
mysql> show variables like '%datadir%';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> show variables like '%log_err%';
+----------------------------+----------------------------------------+
| Variable_name | Value |
+----------------------------+----------------------------------------+
| binlog_error_action | ABORT_SERVER |
| log_error | /var/log/mysql/error.log |
| log_error_services | log_filter_internal; log_sink_internal |
| log_error_suppression_list | |
| log_error_verbosity | 2 |
+----------------------------+----------------------------------------+
5 rows in set (0.00 sec)
# read and write
CREATE USER 'auser'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'auser'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
# read only
CREATE USER 'ruser'@'%' IDENTIFIED BY '123456';
GRANT SELECT ON *.* TO 'ruser'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
# dump
CREATE USER 'duser'@'localhost' IDENTIFIED BY '123456';
GRANT SELECT, LOCK TABLES, PROCESS ON *.* TO 'duser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
-- 添加
CREATE USER 'aaa'@'localhost' IDENTIFIED BY '123456';
-- 删除
DROP USER 'aaa'@'localhost';
ALTER USER 'auser'@'%' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY '234567';
FLUSH PRIVILEGES;
# 关闭服务
sudo service mysql stop
# 安全模式启动服务,跳过权限检查
sudo mysqld_safe --skip-grant-tables &
mysql -uroot -p
--先刷新权限
flush privileges;
-- 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
--再刷新权限
flush privileges;
-- 退出
exit
# 关闭服务
sudo service mysql stop
# 正常启动服务
sudo systemctl start mysql
mysql -uroot -p
vim /usr/bin/mysql_dump.sh
#!/bin/bash
name=mysql_dump_`date '+%Y%m%d_%H%M'`.sql.gz
mysqldump -uduser-P3306 -p123456 -B dbname | gzip > /bak/db/$name
chmod -R 755 /usr/bin/mysql_dump.sh
crontab -e
20 1 * * * /usr/bin/mysql_dump.sh
# 查看防火墙状态
sudo ufw status
# 关闭防火墙
sudo ufw disable
# 开启防火墙
sudo ufw enable
# 开放端口
sudo ufw allow 3306
# 立即生效
sudo ufw reload
# 查看已开放端口
netstat -ntpl
# 远程连接
mysql -hIP -u账号 -P端口 -p