官网下载win64压缩包;
我是解压在c盘下新建的web文件中
然后打开C:\web\mysql-8.0.13-winx64,创建my.ini文件
文件内容
[client]
port = 3308
default-character-set = UTF8MB4
[mysqld]
port = 3308
character_set_server = UTF8MB4
basedir=C:\web\mysql-8.0.13-winx64
datadir=C:\web\mysql-8.0.13-winx64\data
group_concat_max_len=20000
[WinMySQLAdmin]
C:\web\mysql-8.0.13-winx64\bin\mysqld.exe
然后在管理员权限下的cmd中选择进入其中的bin目录
cd C:\web\mysql-8.0.13-winx64\bin
接着输入
mysqld --initialize --console
出现密码+V0x;iq!7n=F,并报了一个错误,不过我在之前的代码中已经改了过来。
C:\web\mysql-8.0.13-winx64\bin>mysqld --initialize --console
2018-11-30T03:44:42.553357Z 0 [System] [MY-013169] [Server] C:\web\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server in progress as process 60624
2018-11-30T03:44:42.555732Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2018-11-30T03:44:46.075302Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: +V0x;iq!7n=F
2018-11-30T03:44:47.177814Z 0 [System] [MY-013170] [Server] C:\web\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server has completed
然后是创建服务器和创建用户
C:\web\mysql-8.0.13-winx64\bin>mysqld --install MySQL8.0 #安装服务
Service successfully installed.
C:\web\mysql-8.0.13-winx64\bin>net start MySQL8.0 #开始服务,服务器名MySQL8.0
MySQL8.0 服务正在启动 .
MySQL8.0 服务已经启动成功。
C:\web\mysql-8.0.13-winx64\bin>mysql -u root -p #登录
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13
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.
#更改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '*******';
Query OK, 0 rows affected (0.09 sec)
mysql> CREATE USER 'ghfuidy'@'%' IDENTIFIED WITH mysql_native_password BY '*******';
Query OK, 0 rows affected (0.01 sec)
#显示所有数据库
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
#使用数据库
mysql> user information_schema;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user information_schema' at line 1
mysql> show tables
-> ;
ERROR 1046 (3D000): No database selected
mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
33 rows in set (0.01 sec)
#查看所有用户状态
mysql> select host,user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | ghfuidy |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)