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:\database\3307
C:\database\3306
二:修改配置文件
C:\database\3306\my-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:\database\3307\my-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:\database\3306\bin
mysqld install 3306 --defaults-file="C:\database\3307\my-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:\database\3307\bin
mysqld install 3307 --defaults-file="C:\database\3307\my-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:\database\3307\bin
mysql -u root -p -P 3307
mysql -u root -p -P 3307
四:如果你忘了自己數據庫的用戶名和密碼:
你需要跳過授權表登錄,就是不需要輸入密碼就可以進入數據庫,然后通過sql命令修改數據庫root的密碼:
1:關閉mysql服務
net stop 3306
2:啟動mysql服務
cd c:\database\3307\bin
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:\database\3306\bin>net stop 3306 3306 服務正在停止. 3306 服務已成功停止。 c:\database\3306\bin>mysqld --remove 3306 Service successfully removed. c:\database\3306\bin>mysqld install 3306 --defaults-file="c:\database\3306\my.ini" Service successfully installed. c:\database\3306\bin>net start 3306 3306 服務正在啟動 . 3306 服務已經啟動成功。 c:\database\3306\bin>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:\database\3306\share\charsets\ | +--------------------------+----------------------------------+ 8 rows in set (0.00 sec) mysql> exit Bye c:\database\3306\bin>net stop 3307 3307 服務正在停止. 3307 服務已成功停止。 c:\database\3306\bin>mysqld --remove 3307 Service successfully removed. c:\database\3306\bin>mysqld --remove 3307 Service successfully removed. c:\database\3306\bin>mysqld install 3307 --defaults-file="c:\database\3307\my.ini" Service successfully installed. c:\database\3306\bin>net start 3307 3307 服務正在啟動 . 3307 服務已經啟動成功。 c:\database\3306\bin>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:\database\3307\share\charsets\ | +--------------------------+----------------------------------+ 8 rows in set (0.00 sec) mysql> exit Bye