Ubuntu 20安装mysql8(apt安装)

查看Ubuntu版本信息:
(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~#

搜索安装:
apt search mysql-server # apt搜索mysql包(ubuntu20 apt 源里的mysql 已经更新到 8.0, 可以直接安装)
sudo apt update # 更新源
sudo apt install mysql-server #安装

安装完成后查看msyql版本:
(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# mysql -V
mysql  Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

mysql 服务的状态管理
systemctl status mysql # 查看状态,装完后默认就启动了,默认开机启动
systemctl disable mysql # 关闭开机启动
systemctl disable mysql # 设置开机启动
systemctl start mysql # 启动 mysql 服务
systemctl stop mysql # 关闭 mysql 服务

默认用户
mysql # 使用 root 用户连入 mysql, 默认不需要密码
cat /etc/mysql/debian.cnf # 这里提供了另一个默认账户和密码 debian-sys-maint,密码是明文,只能在本地登录

我们使用mysql空密码登陆,输入:mysql -uroot -p后回车,显示输入密码,第一次登陆默认密码为空,直接回车即可登录mysql(base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
登陆mysql后我们先修改一下root账号密码,密码规则这里是长度为8位,有大写字母,小写字母。还有特符号。
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>show databases;
mysql>use mysql;
mysql>CREATE USER 'root'@'%' IDENTIFIED BY 'Abcd@1234';
mysql>GRANT ALL ON *.* TO 'root'@'%';
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Abcd@1234';
mysql>FLUSH PRIVILEGES;

允许远程连接
mysql默认只能从本地登录,允许从远程登录需要修改绑定地址.
修改配置文件,绑定ip修改为 0.0.0.0
vim /etc/mysql/mysql.conf.d/mysqld.cnf

#bind-address = 127.0.0.1
bind-address = 0.0.0.0

重启mysql服务
systemctl restart mysql.service

 

发布者:songJian   点击数:493   发布时间:2023-03-13 11:59:46   更新时间:2023-03-13 12:13:11
正在加载评论...
相关文章