Debian 安装 MySQL 8.0.x

2024-07-11  本文已影响0人  Rinaloving

下载MySQL

1. 下载 MySQL 源

以最新为例
下载地址:https://dev.mysql.com/downloads/repo/apt/

image.png

2. 安装MySQL 源

安装源

sudo dpkg -i mysql-apt-config_0.8.32-1_all.deb

安装源时,选择8.0;


image.png

安装MySQL源


image.png

选择8.0


image.png
更新源
sudo apt update

验证源

sudo apt-cache policy mysql-server
image.png

卸载源(记录命令,实际无需操作)

sudo apt purge mysql-apt-config

3. 安装MySQL 服务

sudo apt-get -y install mysql-server

安装过程 - 界面设置密码


image.png
image.png

到这,基本就安装完成了;

安装后,默认已启动,默认开机自启动。

4. 查看MySQL 状态

sudo systemctl status mysql
image.png

配置取消大小写敏感

停止服务

systemctl stop mysql

修改 vim /etc/mysql/mysql.conf.d/mysqld.cnf 配置,添加 lower_case_table_names=1,保存退出。

image.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
image.png

查看MySQL编码,默认为utf8mb4。

 show variables like '%character%'
image.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;

image.png

7.设置防火墙规则,允许3306端口被访问

sudo ufw allow 3306
image.png

按如上步骤执行后,可连接成功。


image.png
上一篇下一篇

猜你喜欢

热点阅读