[mysql]
#设置MySQL客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port = 3306
#设置MySQL的安装目录
basedir =D:\Program Files\MySQL\mysql-8.0.22-winx64
#设置MySQL数据库的数据的存放目录
datadir = D:\Program Files\MySQL\mysql-8.0.22-winx64\data
#允许最大连接数
max_connections=20
#服务端使用字符集默认为8比特编码的latin1字符集
character-set-server=utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
C:\WINDOWS\system32>mysqld install
The service already exists!
The current server installed:
C:\WINDOWS\system32>mysqld remove
Service successfully removed.
C:\WINDOWS\system32>mysqld install
Service successfully installed.
C:\WINDOWS\system32>mysqld --initialize-insecure
C:\WINDOWS\system32>net start mysql
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。
C:\WINDOWS\system32>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22 MySQL Community Server - GPL
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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
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 |
| replication_asynchronous_connection_failover |
| 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 |
+----------------------------------------------+
34 rows in set (0.00 sec)
2.user表中管理用户名与密码因此我们在这张表里面去修改,命令:
alter user ‘root’ @‘localhost’ identified by ‘123456’;
mysql> alter user ‘root‘ @‘localhost‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.15 sec)
3.改完记得重新加载权限表,命令:flush privileges;
mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
4.退出mysql重进,命令:mysql -u root
C:\WINDOWS\system32>mysql -u root
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
5.输入命令:mysql -u root -p
C:\WINDOWS\system32>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.22 MySQL Community Server - GPL
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>
很多用户在使用Navicat Premium 12连接MySQL数据库时会出现Authentication plugin ‘caching_sha2_password’ cannot be loaded的错误。出现这个原因是mysql 8 之前的版本中加密规则是mysql_native_password,而在mysql 8之后,加密规则是caching_sha2_password, 解决问题方法有两种,一种是升级navicat驱动,一种是把mysql用户登录密码加密规则还原成mysql_native_password.
mysql> use mysql;
Database changed
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘123456‘;
Query OK, 0 rows affected (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | mysql_native_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
然后重复一步骤,出现如下错误:
在步骤2中就发现不能远程,设置如下:
mysql> update user set Host=‘%‘ where User=‘root‘;
Query OK, 1 row affected (0.12 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
mysql> select host,plugin,user from user;
+-----------+-----------------------+------------------+
| host | plugin | user |
+-----------+-----------------------+------------------+
| % | mysql_native_password | root |
| localhost | caching_sha2_password | mysql.infoschema |
| localhost | caching_sha2_password | mysql.session |
| localhost | caching_sha2_password | mysql.sys |
+-----------+-----------------------+------------------+
4 rows in set (0.01 sec)
原文:https://www.cnblogs.com/cndeveloper/p/14379948.html