初始化mysql,得到初始密码

#root @ modao in ~/WebServer on git:master o [22:43:30] C:1
$ mysqld --initialize --user=mysql
2020-11-14T14:45:28.700800Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_Z
ERO_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.
2020-11-14T14:45:28.701073Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysql
d 8.0.21) initializing of server in progress as process 6223
2020-11-14T14:45:28.713666Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-11-14T14:45:29.860559Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-11-14T14:45:31.818442Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: HX<U/kZ/U6K0

配置开机自启,启动mysql

#root @ modao in ~/WebServer on git:master o [22:45:35]
$ systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

#root @ modao in ~/WebServer on git:master o [22:49:21]
$ systemctl start mysqld.service

登录mysql,修改密码

#root @ modao in ~/WebServer on git:master o [22:49:41]
$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21

Copyright (c) 2000, 2020, 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.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED 'modao';

创建table,插入数据

mysql> create database webserver;
Query OK, 1 row affected (0.01 sec)

mysql> use webserver;
Database changed
mysql> create table user(
    -> username char(50) NULL,
    -> password char(50) NULL
    -> )ENGINE=InnoDB;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into user(username, password) values ('name', 'password');
Query OK, 1 row affected (0.03 sec)