ubuntu 启动停止 mysql

ubuntu 启动停止 mysql

1. 安装mysql

sudo apt update
sudo apt install mysql-server

2. 检查mysql是否安装

mysql --version

出现类似这样的代表正确安装

Server version: 8.0.33-0ubuntu0.20.04.2 (Ubuntu)

3. 启动mysql

使用如下两个命令可启动mysql

sudo service mysql start
sudo systemctl start mysql

可能会让输入密码,输入即可

4. 检查mysql服务状态

使用如下两个命令可检查服务状态

sudo service mysql status
sudo systemctl status mysql

出现如下代表正确启动

Jul 28 05:32:12 ubuntu systemd[1]: Starting MySQL Community Server...
Jul 28 05:32:15 ubuntu systemd[1]: Started MySQL Community Server.

否则重复3

5. 登录mysql

sudo mysql

出现如下为正确启动

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.33-0ubuntu0.20.04.2 (Ubuntu)

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> 

6. 查看数据库

SHOW DATABASES;

7. 创建数据库

CREATE DATABASE mydb1;

默认字符集的方式创建了mydb1的数据库

8. 选择数据库

USE mydb1;

使用mydb1这个数据库

9. 查看表

SHOW TABLES;

10. 退出数据库

quit;

11. 关闭服务

用其中一个

sudo service mysql stop
sudo systemctl stop mysql
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值