MySQL安装

由于发布时间久远,此文章可能已经过时!

下载安装包,解压

命令行进入其中的bin目录,执行

1
mysqld install

初始化:

1
mysqld --initialize --console

启动:

1
net start mysql

登录:

1
mysql -p密码 -u root -h localhost --default-character-set=utf8

-p密码之间不需要空格

密码在data文件夹中的.err中

1
2
3
4
5
6
7
2019-07-09T06:01:57.352010Z 0 [System] [MY-013169] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server in progress as process 9640
2019-07-09T06:02:01.740043Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ot(=tBs2!a7W
2019-07-09T06:02:03.209213Z 0 [System] [MY-013170] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server has completed
2019-07-09T06:02:06.302561Z 0 [System] [MY-010116] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld (mysqld 8.0.16) starting as process 8992
2019-07-09T06:02:08.875545Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-07-09T06:02:08.916009Z 0 [System] [MY-010931] [Server] D:\Program Files\mysql-8.0.16-winx64\bin\mysqld: ready for connections. Version: '8.0.16' socket: '' port: 3306 MySQL Community Server - GPL.
2019-07-09T06:02:09.169370Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060

这里的随机密码是:ot(=tBs2!a7W

修改初始密码:

1
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

CentOS安装MySQL 8.0.23

安装官方源

1
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

安装

1
yum -y install mysql57-community-release-el7-10.noarch.rpm
1
yum -y install mysql-community-server

启动

1
systemctl start  mysqld.service

找到密码:

1
grep "password" /var/log/mysqld.log

忘记密码:

1
$ vim /etc/my.cnf

[mysqld]的段中加上一句:skip-grant-tables
例如:

1
2
3
4
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables

重新启动mysqld

1
$ service mysqld restart

登录并修改MySQLroot密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> USE mysql;
Database changed

mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit

删除跳过密码,然后重启MySQL

使用空密码登陆

修改密码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

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

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×