Ubuntu安装MySQL数据库
介绍
MySQL 的定义
MySQL 是一种开源关系型数据库管理系统。与其他关系型数据库一样,MySQL 将数据存储在由行和列组成的表中。用户可以使用结构化查询语言(通常称为 SQL)定义、操作、控制和查询数据。由于 MySQL 是开源的,因此它的大量功能是在超过 25 年与用户密切合作的过程中开发出来的。
MySQL 软件是开源的
MySQL 是开源的,这意味着按照 GNU 通用公共许可条款,该工具可以免费使用。这也意味着,任何人都可以根据自己的使用需求自由修改软件的源代码。这使得 MySQL 分支为其他数据库变体(例如 MariaDB 和 Percona Server for MySQL)。MySQL 也可以通过其他许可用于商业用途。
关系型数据库
MySQL 所属的数据库类别称为关系型数据库管理系统 (RDBMS)。关系型数据库是信息的集合,它以预定义的关系组织数据,数据存储在一个或多个由列和行构成的表(或称“关系”)中,用户可以轻松查看和理解不同数据结构之间的关系。关系是不同表之间的逻辑连接,根据这些表之间的交互建立。
下载
下载地址https://dev.mysql.com/downloads/
在此页面中,需要选择你要安装的版本类型,我这里是Ubuntu系统所以选择 MySQL APT Repository,若你使用CentOS那么就使用MySQL Yum Repository
#下载地址
# https://dev.mysql.com/downloads/
# 选择你要安装的版本类型,我这里是Ubuntu系统所以选择 MySQL APT Repository,若你使用CentOS那么就使用MySQL Yum Repository
apt install https://dev.mysql.com/get/mysql-apt-config_0.8.28-1_all.deb
# 安装MySQL-Server
apt install mysql-community-server
# 查看服务是否正常
root@cby:~# systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-12-06 15:35:30 CST; 22min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 9786 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 3943)
Memory: 369.3M
CPU: 3.989s
CGroup: /system.slice/mysql.service
└─9786 /usr/sbin/mysqld
Dec 06 15:35:29 cby systemd[1]: Starting MySQL Community Server...
Dec 06 15:35:30 cby systemd[1]: Started MySQL Community Server.
root@cby:~#
开启外部访问
# 登录数据库
root@cby:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.35 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
# 选择使用mysql库
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>
mysql>
# 查询用户表
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | $A$005$yWgZ hKW4{ege
W/5pMsmD7O.Tq.KL8z9ARsM1TcL74ysSUXrqH0pWKEj5 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
# 修改root的授权
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
mysql>
mysql> Grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql>
# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql>
mysql> ^DBye
root@cby:~#
root@cby:~#
测试
# 使用其他主机进行登录数据库
root@cby:~# mysql -u root -p -h x.oiox.cn
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.35 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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>
mysql> ^DBye
root@cby:~#
root@cby:~#