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