mysql community server 8.0.12安装配置方法图文教程

作者:_waylau 时间:2024-01-21 19:28:04 

MySQL 8 带来了全新的体验,比如支持 NoSQL、JSON 等,拥有比 MySQL 5.7 两倍以上的性能提升。本文讲解如何在 Windows 下安装 MySQL 8,以及基本的 MySQL 用法。

下载

下载地址

本例为:MySQL Community Server 8.0.12。

解压

解压至安装目录,比如 D 盘根目录下。

本例为:D:\mysql-8.0.12-winx64。

创建 my.ini

my.ini 是 MySQL 安装的配置文件:


[mysqld]
# 安装目录
basedir=D:\\mysql-8.0.12-winx64
# 数据存放目录
datadir=D:\\mysqlData\\data

my.ini放置在 MySQL 安装目录的根目录下。需要注意的是,要先创建D:\mysqlData目录。data目录是由 MySQL 来创建。

初始化安装

执行:


mysqld --defaults-file=D:\mysql-8.0.12-winx64\my.ini --initialize --console

控制台输出如下,说明安装成功:


>mysqld --defaults-file=D:\mysql-8.0.12-winx64\my.ini --initialize --console
2018-08-20T16:14:45.287448Z 0 [System] [MY-013169] [Server] D:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 5012
2018-08-20T16:14:45.289628Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2018-08-20T16:14:45.299329Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-08-20T16:14:45.301316Z 0 [System] [MY-010910] [Server] D:\mysql-8.0.12-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.12) MySQL Community Server - GPL.

D:\mysql-8.0.12-winx64\bin>mysqld --defaults-file=D:\mysql-8.0.12-winx64\my.ini --initialize --console
2018-08-20T16:15:25.729771Z 0 [System] [MY-013169] [Server] D:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 18148
2018-08-20T16:15:43.569562Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: L-hk!rBuk9-.
2018-08-20T16:15:55.811470Z 0 [System] [MY-013170] [Server] D:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server has completed

其中,“L-hk!rBuk9-.”就是 root 用户的初始化密码。稍后可以做更改。

启动、关闭 MySQL server

执行mysqld就能启动 MySQL server,或者执行 mysqld –console可以看到完整的启动信息:


>mysqld --console
2018-08-20T16:18:23.698153Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-08-20T16:18:23.698248Z 0 [System] [MY-010116] [Server] D:\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) starting as process 16304
2018-08-20T16:18:27.624422Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-08-20T16:18:27.793310Z 0 [System] [MY-010931] [Server] D:\mysql-8.0.12-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.12' socket: '' port: 3306 MySQL Community Server - GPL.

关闭,可以执行 mysqladmin -u root shutdown。

使用 MySQL 客户端

使用 mysql 来登录,账号为 root,密码为“L-hk!rBuk9-.”:


>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.12

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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.

执行下面的语句来改密码。其中“123456”即为新密码。


mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.13 sec)

MySQL 常用指令

显示已有的数据库:


mysql> show databases;
+--------------------+
| Database  |
+--------------------+
| information_schema |
| mysql  |
| performance_schema |
| sys  |
+--------------------+
4 rows in set (0.08 sec)

创建新的数据库:


mysql> CREATE DATABASE lite;
Query OK, 1 row affected (0.19 sec)

使用数据库:


mysql> USE lite;
Database changed

建表:

建表执行:


mysql> CREATE TABLE t_user (user_id BIGINT NOT NULL, username VARCHAR(20));
Query OK, 0 rows affected (0.82 sec)

查看表:

查看数据库中的所有表:


mysql> SHOW TABLES;
+----------------+
| Tables_in_lite |
+----------------+
| t_user  |
+----------------+
1 row in set (0.00 sec)

查看表的详情:


mysql> DESCRIBE t_user;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| user_id | bigint(20) | NO | | NULL | |
| username | varchar(20) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

插入数据:


mysql> INSERT INTO t_user(user_id, username) VALUES(1, '老卫');
Query OK, 1 row affected (0.08 sec)

来源:https://blog.csdn.net/kkkloveyou/article/details/81880673

标签:mysql8.0,mysql8.0.12
0
投稿

猜你喜欢

  • python fuzzywuzzy模块模糊字符串匹配详细用法

    2021-10-02 10:58:03
  • selenium在scrapy中的使用代码

    2021-11-24 09:34:16
  • python实现银行账户系统

    2023-05-27 17:49:08
  • 2009淘宝网动画节日LOGO第一季

    2009-05-18 19:11:00
  • 如何用表单在线建立目录?

    2010-06-16 09:49:00
  • Python实现读取csv文件并进行排序

    2021-06-27 08:37:59
  • pycharm 终端部启用虚拟环境详情

    2022-04-01 17:52:59
  • PHP抓取及分析网页的方法详解

    2023-11-24 08:17:10
  • Python Pygame实战之赛车游戏的实现

    2022-09-17 12:12:14
  • 通过SQL绘制杨辉三角的实现方法介绍

    2024-01-27 04:08:49
  • 在SQL Server中处理空值时涉及的三个问题

    2009-02-05 15:30:00
  • asp截取字符串的两种应用

    2009-08-19 17:11:00
  • SQLite Delete详解及实例代码

    2024-01-12 17:15:46
  • Python实现简易的图书管理系统

    2021-09-12 06:06:21
  • 利用location.hash实现跨域iframe自适应高宽

    2009-08-02 20:31:00
  • python使用rstrip函数删除字符串末位字符

    2023-06-10 16:59:56
  • 九步学会Python装饰器

    2021-04-05 15:35:07
  • php中实现记住密码自动登录的代码

    2023-11-14 18:36:14
  • optgroup、sub、sup和bdo标签

    2009-07-26 18:39:00
  • 详解vue中$nextTick和$forceUpdate的用法

    2024-06-05 09:15:44
  • asp之家 网络编程 m.aspxhome.com