在前面的安装操作中我们一直没有设置root密码,所以在验证之前我们要设置一下root密码,按照下面的步骤操作即可;密码设置完成后即可登录进行常规操作,如下即表示安装成功。
C:\mysql-8.0.13-winx64\bin>mysqladmin -u root password Smart@123 mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. C:\mysql-8.0.13-winx64\bin>mysql -uroot -p Enter password: ********* Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.13 MySQL Community Server - GPL 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> show databases ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) mysql> 补充内容 实际上这种免安装模式是将MySQL注册为Windows的一个服务了,通过查看服务列表我们能发现这个MySQL服务,也可以控制服务的启动方式、运行状态等等。
首先要停止当前正在运行的服务,然后删除mysql目录
然后打开注册表编辑器(regedit),找到并清除以下项:
HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/Eventlog/Application/MySQLD Service
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Eventlog/Application/MySQLD Service
最后需要删除已注册到系统中的MySQL服务
C:\Windows\system32>sc delete MySQL [SC] DeleteService 成功 C:\Windows\system32> 小葵花补充知识点 关于密码规则MySQL的密码设置有不同的规则等级,具体说来是跟validate_password_policy这个配置相关的(默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。):
Policy Tests Performed0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file
忘记密码了怎么办?
有时长时间不用某服务器了,猛地有一天想去看看数据却发现密码忘了,很是尴尬吧?这时候就需要用到了skip-grant-tables 这个配置了,在my.cnf中将这个配置项打开然后restart一下服务,就可以不用校验密码登录mysql服务器了,登录进去之后再给自己的root重新设置一下密码update mysql.user set authentication_string=password('Smart@123') where user='root' ;,大功告成!
[root@mserver0002 img]# cat /etc/my.cnf [mysqld] ####basic settings#### #skip-grant-tables default-storage-engine=INNODB ...... # 修改完配置文件后可以使用空密码登录(在Enter password:出现后直接敲enter键) [root@ecs-ce5a-0001 etc]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ...... mysql> use mysql Database changed mysql> SET PASSWORD = PASSWORD('Smart@123'); ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Smart@123'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> update mysql.user set password=password('Smart@123') where user= 'root'; ERROR 1054 (42S22): Unknown column 'password' in 'field list' mysql> desc mysql.user -> ; +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Host | char(60) | NO | PRI | | | ...... | authentication_string | text | YES | | NULL | | | password_expired | enum('N','Y') | NO | | N | | | password_last_changed | timestamp | YES | | NULL | | | password_lifetime | smallint(5) unsigned | YES | | NULL | | | account_locked | enum('N','Y') | NO | | N | | +------------------------+-----------------------------------+------+-----+-----------------------+-------+ 45 rows in set (0.00 sec) mysql> update mysql.user set authentication_string=password('Smart@123') where user= 'root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye [root@ecs-ce5a-0001 etc]# mysql -uroot -p # 在这里输入新设置的密码Smart@123 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ...... mysql> 关于赋权的说明