一、下载链接地址:
https://dev.mysql.com/downloads/mysql/ #下载完成后直接解压即可
二、windows下初始化MySQL
1、把MySQL的解压路径加入到系统环境变量中
2、把MySQL设置为windows服务
C:\Users\test>mysqld --install #安装 C:\Users\test>mysqld --remove #从windows服务中删除 C:\Users\test>net start/stop mysql #启动或停止MySQ服务
3、用MySQL自带客户端登陆到MySQL,并查看当前登陆的用户,默认为ODBC
1 C:\Users\Jun>mysql
2 mysql> select user();
3 +----------------+
4 | user() |
5 +----------------+
6 | ODBC@localhost |
7 +----------------+
8 1 row in set (0.00 sec)
9 [root@db01 mysql]# mysqladmin -uroot password 123456 #设置root密码
10 [root@db01 mysql]# mysqladmin -uroot -p123456 password 1234 #更改root密码
11 [root@db01 mysql]# mysqladmin -uroot -p1234 password "" # 把root用户的密码设置为空密码
4、Linux下密码破解
1 [root@db01 mysql]# vim my.cnf
2 [mysql]
3 user=root
4 password=123456
5 [mysqld]
6 skip-grant-tables #在my.cnf文件中加上这句(跳过mysql授权表)
7
8 [root@db01 mysql]# /etc/init.d/mysqld restart #重启MySQL服务
9 [root@db01 mysql]# mysql #登录MySQL
10 mysql> select user(); #查看登录用户是否为root
11 +--------+
12 | user() |
13 +--------+
14 | root@ |
15 +--------+
16 1 row in set (0.00 sec)
17
18 mysql> update mysql.user set password=password("123") where user="root" and host="localhost"; #修改密码为123
19 mysql> flush privileges;
注:windows下密码破解可以使用和Linux上相同的方法
windows下另外破解密码方法
1 C:\Users\test>net stop mysql 2 C:\Users\test>mysqld --skip-grant-tables 3 C:\Users\test>mysql 4 mysql> update mysql.user set authentication_string=password(‘‘) where user = ‘root‘; 5 mysql> flush privileges; 6 C:\Users\test>net start mysql
5、指定登录用户名和密码和查看MySQL字符集
1 C:\Users\test>mysql -uroot -p123456
2 mysql> select user();
3 +----------------+
4 | user() |
5 +----------------+
6 | root@localhost |
7 +----------------+
8 1 row in set (0.00 sec)
9 mysql> show variables like ‘%char%‘; #查看数据库字符集
10 +--------------------------+-------------------------------------------+
11 | Variable_name | Value |
12 +--------------------------+-------------------------------------------+
13 | character_set_client | utf8 |
14 | character_set_connection | utf8 |
15 | character_set_database | latin1 |
16 | character_set_filesystem | binary |
17 | character_set_results | utf8 |
18 | character_set_server | latin1 |
19 | character_set_system | utf8 |
20 | character_sets_dir | /application/mysql-5.6.35/share/charsets/ |
21 +--------------------------+-------------------------------------------+
22 8 rows in set (0.02 sec)
6、mysql客户端免输入用名密码登录及修改默认字符集
在mysql配置文件中加上(windows上为my.ini,Linux上为my.cnf)
[mysql]
default-character-set=utf8
user=root
password=123456
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
skip-grant-tables
C:\Users\Jun>mysql #登录MySQL
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)