mysql community server 8.0. 12 Installation Configuration Tutorial

  • 2021-11-02 03:01:11
  • OfStack

MySQL 8 brings new experiences, such as supporting NoSQL, JSON, etc., and has more than twice the performance improvement compared with MySQL 5.7. This article explains how to install MySQL 8 under Windows and basic MySQL usage.

Download

Download address

This example is: MySQL Community Server 8.0. 12.

Decompression

Unzip to the installation directory, such as the root directory of D disk.

This example is: D:\ mysql-8. 0.12-winx64.

Create my. ini

my. ini is the configuration file for the MySQL installation:


[mysqld]
#  Installation directory 
basedir=D:\\mysql-8.0.12-winx64
#  Data storage directory 
datadir=D:\\mysqlData\\data

my. ini is placed at the root of the MySQL installation directory. It should be noted that the D:\ mysqlData directory should be created first. The data directory is created by MySQL.

Initialize the installation

Execution:


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

The console output is as follows, indicating that the installation was successful:


>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

Where, "L-hk! rBuk9-." is the initialization password of the root user. You can make changes later.

Start and close MySQL server

Execute mysqld to start MySQL server, or execute mysqld console to see the complete startup information:


>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.

Off, mysqladmin-u root shutdown can be executed.

Using the MySQL client

Use mysql to log in, account number is root, password is "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.

Execute the following statement to change the password. Where "123456" is the new password.


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

MySQL Common Instructions

Display existing databases:


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

Create a new database:


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

Using a database:


mysql> USE lite;
Database changed

Form building:

Form building and execution:


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

View table:

View all the tables in the database:


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

View the details of the table:


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

Insert data:


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

Related articles: