1. 程式人生 > 其它 >mysql安裝及改埠

mysql安裝及改埠

mysql 8.0.19 安裝 及 埠修改

1.建立my.ini檔案

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # 設定3309埠 port=3309#根據自己的需要修改埠 # 設定mysql的安裝目錄 basedir=L:\1_mysql\mysql-8.0.19-winx64#根據自己的檔案位置修改 # 設定mysql資料庫的資料的存放目錄 datadir=L:\1_mysql\mysql-8.0.19-winx64\Data#根據自己的檔案位置修改 # 允許最大連線數 max_connections=200
# 允許連線失敗的次數。這是為了防止有人從該主機試圖攻擊資料庫系統 max_connect_errors=10 # 服務端使用的字符集預設為UTF8 character-set-server=utf8 # 建立新表時將使用的預設儲存引擎 default-storage-engine=INNODB # 預設使用“mysql_native_password”外掛認證 default_authentication_plugin=mysql_native_password sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
[mysql] # 設定mysql客戶端預設字符集 default-character-set=utf8 [client] # 設定mysql客戶端連線服務端時預設使用的埠 port=3309#根據自己的需要修改埠 default-character-set=utf8

2.解壓mysql-8.0.19-winx64.zip到安裝目錄;
3.將my.ini檔案複製到mysql-8.0.19-winx64根目錄;
4.進入mysql-8.0.19-winx64\bin資料夾,在此資料夾下開啟Powershell視窗;
5.安裝mysql,
輸入:
mysqld --install
返回:
Service successfully installed.
6.初始化mysql,
輸入:
mysqld --initialize --console
返回:
2020-05-21T01:51:15.619733Z 0 [System] [MY-013169] [Server] L:\1_mysql\mysql-8.0.19-winx64\bin\mysqld.exe (mysqld 8.0.19) initializing of server in progress as process 328
2020-05-21T01:51:15.622433Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2020-05-21T01:51:30.165449Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: e-%Uh<=ga1qp
7.啟動mysql,
輸入:
net start mysql
回顯:
MySQL 服務正在啟動 ..
MySQL 服務已經啟動成功。
8.登入mysql,
輸入:
mysql -u root -p
回顯:
Enter password: "輸入密碼"
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

Copyright (c) 2000, 2020, 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.

9.修改密碼:
輸入:
ALTER user 'root'@'localhost' IDENTIFIED BY '新密碼';
回顯:
Query OK, 0 rows affected (0.34 sec)
10.檢視埠號:
輸入:
show global variables like 'port';
回顯:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3309 |
+---------------+-------+
1 row in set, 1 warning (0.01 sec)


11.其它操作
停止mysql服務:

net stop mysql

刪除mysql:

mysqld -remove mysql
刪除服務:

sc delete mysql

查詢user表,看host和user情況

select user,host from user;

修改MySQL登入主機名稱(所有主機):

update user set host = '%' where user = 'root';

重新整理MySQL的系統許可權相關表:

flush privileges;

切換使用的資料庫:

usemysql