首页 > 数据库 >Ubuntu Server 20.04 安装MySQL

Ubuntu Server 20.04 安装MySQL

时间:2024-11-16 10:41:37浏览次数:1  
标签:10 sudo Server mysql MySQL password 20.04 ubuntu

1. 通过apt安装MySQL

1 #命令1
2 sudo apt-get update
3 #命令2
4 sudo apt-get install mysql-server

2. 配置mysql初始化信息

1 sudo mysql_secure_installation

配置说明:

复制代码
ubuntu@VM-0-10-ubuntu:~$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N(选择N,不会进行密码的强校验)
Please set the password for root here.

New password: 

Re-enter new password: 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : N(选择N,不删除匿名用户)

 ... skipping.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N(选择N,允许root远程连接)

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N(选择N,不删除test数据库)

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y(选择Y,修改权限立即生效)
Success.

All done! 
复制代码

3. 创建数据库

1 #1 创建数据库TestDB
2 CREATE DATABASE TestDB;

4. 配置访问权限

复制代码
1 # 登陆mysql
2 sudo mysql -uroot -p
3 #切换数据库
4 use mysql;
5 #查询用户表命令:
6 select User,Host from user;
复制代码 复制代码
 1 ubuntu@VM-0-10-ubuntu:~$ ubuntu@VM-0-10-ubuntu:~$ sudo mysql -u root -p
 2 Enter password:
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 29
 5 Server version: 8.0.21-0ubuntu0.20.04.4 (Ubuntu)
 6 
 7 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql> use mysql;
16 Reading table information for completion of table and column names
17 You can turn off this feature to get a quicker startup with -A
18 
19 Database changed
20 mysql> select User,Host from user;
21 +------------------+-----------+
22 | User             | Host      |
23 +------------------+-----------+
24 | Joseph           | %         |
25 | debian-sys-maint | localhost |
26 | mysql.infoschema | localhost |
27 | mysql.session    | localhost |
28 | mysql.sys        | localhost |
29 | root             | localhost |
30 +------------------+-----------+
31 6 rows in set (0.00 sec)
32 
33 mysql>   
复制代码

创建新用户并赋予权限

1 # 创建用户Joseph@'%',密码是‘123456’
2 create user Joseph@'%' identified by '123456';
3 # 赋予其TestDB数据库的远程连接权限
4 grant all privileges on Joseph.* to TestDB;

查看MySQL端口号

复制代码
1 mysql> show global variables like 'port';
2 +---------------+-------+
3 | Variable_name | Value |
4 +---------------+-------+
5 | port          | 3306  |
6 +---------------+-------+
7 1 row in set (0.00 sec)
复制代码

退出MySQL查看3306端口是否正常

复制代码
1 # 退出MySQL
2 mysql> exit
3 Bye
4 # 查看3306端口是否正常
5 ubuntu@VM-0-10-ubuntu:~$ netstat -an | grep 3306
6 tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
7 ubuntu@VM-0-10-ubuntu:~$   
复制代码

注意:现在的3306端口绑定的IP地址是本地的127.0.0.1

修改Mysql配置文件(注意路径)

1 ubuntu@VM-0-10-ubuntu:~$ vim /etc/mysql/mysql.conf.d/mysqld.cnf

找到

bind-address            = 127.0.0.1

前面加#注释掉

5. MySQL服务命令

复制代码
1 # 检查服务状态
2 sudo service mysql status
3 # 停止 MySQL 服务
4 sudo service mysql stop
5 # 启动 MySQL 服务
6 sudo service mysql start
复制代码

6. 腾讯云或者阿里云注意要配置安全组信息放开端口

7. 注意防火墙状态

复制代码
1 # 查看防火墙状态
2 sudo ufw status
3 # 停止防火墙
4 sudo  ufw disable
5 # 启动防火墙
6 sudo  ufw enable
复制代码

标签:10,sudo,Server,mysql,MySQL,password,20.04,ubuntu
From: https://www.cnblogs.com/funiyi816/p/18549108

相关文章

  • 创建一个文章收藏表的mysql
    下面是一个设计合理的文章收藏表(article_favorites)的MySQL表结构,可以用于存储用户收藏文章的记录。表结构设计表名:article_favoritesCREATETABLE`article_favorites`(`id`INTAUTO_INCREMENTPRIMARYKEYCOMMENT'自增ID',`user_id`INTNOTNULL......
  • php开源短视频源码,如何快速修改MySQL的表结构?
    php开源短视频源码,如何快速修改MySQL的表结构?修改表修改MySQL的表结构修改数据库编码格式alterdatabase<数据库名>charactersetutf8mb4; 修改表的编码altertable<表名>charactersetutf8; 修改表的列名#altertable表名changecolum......
  • MiniShopping-mysql数据库
    CREATEDATABASEMiniShopping;USEMiniShopping;CREATETABLEadministrators(idINTUNSIGNEDPRIMARYKEYAUTO_INCREMENTCOMMENT'ID',passwordVARCHAR(256)COMMENT'密码',create_timeDATETIMENOTNULLCOMMENT'创建时间',update_tim......
  • Linux系统-redis集群、nacos、nginx、keepalived、mysql开机自启
    一、Redis集群开机自启:如三主三从交叉式redis集群,有两个方法,自行选择。方法一:第一步:分别在各节点添加以下redis.service文件命令:vim/lib/systemd/system/redis_6379.service添加:[Unit]Description=Redispersistentkey-valuedatabaseAfter=network.targetAfter=......
  • 基于Java+SSM+JSP+MYSQL实现的宠物领养收养管理系统功能设计与实现二
    一、前言介绍:免费学习:猿来入此1.1项目摘要随着人们生活水平的提高,宠物已经成为越来越多家庭的重要成员。然而,宠物的数量增长也带来了一系列问题,如流浪宠物数量的增加、宠物健康管理的缺失以及宠物领养收养信息的不透明等。这些问题不仅影响了宠物的生存状况,也给社会带来了一定......
  • 基于Java+SSM+JSP+MYSQL实现的宠物领养收养管理系统功能设计与实现一
    一、前言介绍:免费学习:猿来入此1.1项目摘要随着人们生活水平的提高,宠物已经成为越来越多家庭的重要成员。然而,宠物的数量增长也带来了一系列问题,如流浪宠物数量的增加、宠物健康管理的缺失以及宠物领养收养信息的不透明等。这些问题不仅影响了宠物的生存状况,也给社会带来了一定......
  • SqlSugarClient 代码优先建表, 根据给定的实体类,创建SQL语句, 之后创建MySQL表
    usingSqlSugar;usingSystem;usingSystem.Collections.Generic;usingSystem.Reflection;usingSystem.Text;namespaceDDD{///<summary>//////SqlSugarClient代码优先建表///根据给定的实体类,创建SQL语句,之后创建MySQL表//////......
  • 27. 使用MySQL之全球化和本地化
    1.字符集和校对顺序数据库表被用来存储和检索数据。不同的语言和字符集需要以不同的方式存储和检索。因此,MySQL需要适应不同的字符集(不同的字母和字符),适应不同的排序和检索数据的方法。在讨论多种语言和字符集时,将会遇到以下重要术语:字符集为字母和符号的集合;编码为某个......
  • MySQL:CRUD
    MySQL表的增删改查(操作的是表中的记录)CRUD(增删改查)C-Create新增R-Retrieve检查,查询U-Update更新D-Delete删除新增(Create)语法:单行数据+全列插入 insertinto表名[字段一,字段二]values(值一,值二); 通过看表的结果,我们可以看出内容已经写好注:列和值的数据类型一定要......
  • MySQL:数据库的约束
    约束类型NOTNULL-指示某列不能存储NULL值。UNIQUE-保证某列的每行必须有唯一的值。DEFAULT-规定没有给列赋值时的默认值。PRIMARYKEY-NOTNULL和UNIQUE的结合。确保某列(或两个列多个列的结合)有唯一标识,有助于更容易更快速地找到表中的一个特定的记录。FOREI......