windows安装多个mysql
下载mysql
配置mysql的文件
启动数据库
如何破解,修改数据库的用户名和密码
一:下载mysql
下载地址:
https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.43-winx64.zip
链接:https://pan.baidu.com/s/1kEFQ_AC56eFUnGwZ44NIwg
提取码:piq1
复制这段内容后打开百度网盘手机App,操作更方便哦
复制下面的文件:如图
我在c盘下面放了这些文件:创建了两个目录3306,3307,将这些文件放在下面:
C:database3307
C:database3306
二:修改配置文件
C:database3306my-default.ini
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
port=3306
basedir=C:/database/3306
datadir=C:/database/3306/data
C:database3307my-default.ini
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
port=3307
basedir=C:/database/3307
datadir=C:/database/3307/data
总结:配置文件只要修改三个内容:port ,basedir ,datadir
三:启动3306,3307的数据库
注意:cmd命令行需要以管理员的身份运行,管理员的权限
执行下面的命令启动3306的mysql
cd C:database3306in
mysqld install 3306 --defaults-file="C:database3307my-default.ini"
net start 3306
mysql -u root
mysql> update mysql.user set password=password("123") where user="root" and host="localhost";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
执行下面的命令启动3306的mysql
cd C:database3307in
mysqld install 3307 --defaults-file="C:database3307my-default.ini"
net start 3307
mysql -u root
mysql> update mysql.user set password=password("123") where user="root" and host="localhost";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
测试:
由于没有设置环境变量,所以测试的时候需要切换到bin目录下,使用mysql客户端的命令来测试数据库服务器是否可以连接,切换到3306或3307的任意一个bin目录下就可以了。
cd c:database3307in
mysql -u root -p -P 3307
mysql -u root -p -P 3307
四:如果你忘了自己数据库的用户名和密码:
你需要跳过授权表登录,就是不需要输入密码就可以进入数据库,然后通过sql命令修改数据库root的密码:
1:关闭mysql服务
net stop 3306
2:启动mysql服务
cd c:database3307in
mysql --skip-grant-tables
3:进入mysql
mysql -u root -p 直接回车,按enter键
4:修改密码
mysql> update mysql.user set password=password("123") where user="root" and host="localhost";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
5:杀掉这个mysql服务的进程
在2步骤直接按ctrl+c 就可以停止服务了
或者
tasklist | findstr mysql
taskkill /F /PID 进程的pid
这个命令适用于单个服务。
6:启动mysql服务
net start 3306
测试:略
7:补充添加字符编码:utf-8
[mysqld] character-set-server=utf8 collation-server=utf8_general_ci [client] default-character-set=utf8 [mysql] default-character-set=utf8
8:重新启动mysql服务3306,3307
c:database3306in>net stop 3306 3306 服务正在停止. 3306 服务已成功停止。 c:database3306in>mysqld --remove 3306 Service successfully removed. c:database3306in>mysqld install 3306 --defaults-file="c:database3306my.ini" Service successfully installed. c:database3306in>net start 3306 3306 服务正在启动 . 3306 服务已经启动成功。 c:database3306in>mysql -u root -p123 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1 Server version: 5.6.43 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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 variables like "%char%" -> ; +--------------------------+----------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | C:database3306sharecharsets | +--------------------------+----------------------------------+ 8 rows in set (0.00 sec) mysql> exit Bye c:database3306in>net stop 3307 3307 服务正在停止. 3307 服务已成功停止。 c:database3306in>mysqld --remove 3307 Service successfully removed. c:database3306in>mysqld --remove 3307 Service successfully removed. c:database3306in>mysqld install 3307 --defaults-file="c:database3307my.ini" Service successfully installed. c:database3306in>net start 3307 3307 服务正在启动 . 3307 服务已经启动成功。 c:database3306in>mysql -u root -p123 -P 3307 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1 Server version: 5.6.43 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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 variables like "%char%"; +--------------------------+----------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | C:database3307sharecharsets | +--------------------------+----------------------------------+ 8 rows in set (0.00 sec) mysql> exit Bye