MySQL使用

0. 前言

。。。

1. 安装MySQL

Ubuntu上直接通过apt-get安装

sudo apt-get install mysql-server

启动服务

sudo service mysql start

停止服务

sudo service mysql stop

初始化配置

sudo mysql_secure_installation

配置选择

(base) kangxiatao@AnoI:~$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.

# 1
VALIDATE PASSWORD COMPONENT 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 component?

Press y|Y for Yes, any other key for No: n

# 2
Please set the password for root here.
New password: 
Re-enter new password: 

# 3
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

# 4
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) : y
Success.

# 5
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

# 6
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

Success.
All done! 

检查mysql服务状态

systemctl status mysql.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL是一种关系型数据库管理系统,它可以用于存储和管理数据。以下是MySQL使用的一些基本步骤: 1. 下载和安装MySQL:您可以从MySQL官方网站下载MySQL安装包,并按照安装向导中的步骤进行安装。 2. 启动MySQL服务器:在安装完成后,您需要启动MySQL服务器。在Windows上,您可以在控制面板中找到MySQL服务并启动它。在Linux上,您可以使用命令行启动MySQL服务。 3. 连接到MySQL服务器:您可以使用MySQL客户端连接到MySQL服务器。在Windows上,您可以使用MySQL Workbench或其他MySQL客户端。在Linux上,您可以使用命令行连接到MySQL服务器。 4. 创建数据库:在MySQL中,您可以使用CREATE DATABASE语句创建一个新的数据库。例如,您可以使用以下命令创建一个名为“mydatabase”的数据库: ``` CREATE DATABASE mydatabase; ``` 5. 创建表:在MySQL中,您可以使用CREATE TABLE语句创建一个新的表。例如,以下命令创建一个名为“customers”的表: ``` CREATE TABLE customers ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50) NOT NULL ); ``` 6. 插入数据:在MySQL中,您可以使用INSERT INTO语句将数据插入到表中。例如,以下命令将一条新记录插入到“customers”表中: ``` INSERT INTO customers (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com'); ``` 7. 查询数据:在MySQL中,您可以使用SELECT语句从表中检索数据。例如,以下命令检索“customers”表中的所有记录: ``` SELECT * FROM customers; ``` 这些是MySQL的一些基本用法。MySQL还有许多其他功能和命令,您可以在MySQL文档中找到更多信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值