下载MySQL
1. 下载 MySQL 源
以最新为例
下载地址:https://dev.mysql.com/downloads/repo/apt/
![](https://img.haomeiwen.com/i14245154/210c8ccc0772b47a.png)
2. 安装MySQL 源
-
本地上传服务器
image.png
安装源
sudo dpkg -i mysql-apt-config_0.8.32-1_all.deb
安装源时,选择8.0;
![](https://img.haomeiwen.com/i14245154/585248ebd6fc2edc.png)
安装MySQL源
![](https://img.haomeiwen.com/i14245154/324c1d8dc5ab29d6.png)
选择8.0
![](https://img.haomeiwen.com/i14245154/ed75985e005eaaac.png)
更新源
sudo apt update
验证源
sudo apt-cache policy mysql-server
![](https://img.haomeiwen.com/i14245154/ab66ab67a6ba199d.png)
卸载源(记录命令,实际无需操作)
sudo apt purge mysql-apt-config
3. 安装MySQL 服务
sudo apt-get -y install mysql-server
安装过程 - 界面设置密码
![](https://img.haomeiwen.com/i14245154/da3e7d9b1fa4c882.png)
![](https://img.haomeiwen.com/i14245154/feb917b141def5a4.png)
到这,基本就安装完成了;
安装后,默认已启动,默认开机自启动。
4. 查看MySQL 状态
sudo systemctl status mysql
![](https://img.haomeiwen.com/i14245154/bdf2ffa417866120.png)
配置取消大小写敏感
停止服务
systemctl stop mysql
修改 vim /etc/mysql/mysql.conf.d/mysqld.cnf
配置,添加 lower_case_table_names=1
,保存退出。
![](https://img.haomeiwen.com/i14245154/6d4fd4108e436fc0.png)
# Copyright (c) 2014, 2024, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is designed to work with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have either included with
# the program or referenced in the documentation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[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
lower_case_table_names=1
启动服务
systemctl start mysql
5.登录MySQL
mysql -uroot -p
![](https://img.haomeiwen.com/i14245154/34ce30396ee9a271.png)
查看MySQL编码,默认为utf8mb4。
show variables like '%character%'
![](https://img.haomeiwen.com/i14245154/423be7335c007cc8.png)
修改MySQL密码
set password for 'root'@'localhost'=password('root');
6. 远程连接
1. 创建新用户
注意:root账号在debian
系统中无法直接开启远程连接,所以需要新建mysql用户;
CREATE USER 'your_username'@'%' IDENTIFIED BY 'your_password';
2. 新用户授权
GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'%' WITH GRANT OPTION;
3. 刷新MySQL权限
FLUSH PRIVILEGES;
4. 软件连接异常
> 1. 修改账户密码加密规则并更新用户密码
ALTER USER 'your_username'@'%' IDENTIFIED BY 'your_password' PASSWORD EXPIRE NEVER;
> 2. 更新一下用户的密码
ALTER USER 'your_username'@'%' IDENTIFIED WITH mysql_native_password BY 'your_password';
> 3. 刷新权限并重置密码
FLUSH PRIVILEGES;
![](https://img.haomeiwen.com/i14245154/83df748b646c42c6.png)
7.设置防火墙规则,允许3306端口被访问
sudo ufw allow 3306
![](https://img.haomeiwen.com/i14245154/0318fa26b5e1b2de.png)
按如上步骤执行后,可连接成功。
![](https://img.haomeiwen.com/i14245154/27bf01d6c9a502b6.png)
网友评论