首頁  >  文章  >  資料庫  >  講解mysql8.0的部分簡單配置

講解mysql8.0的部分簡單配置

藏色散人
藏色散人轉載
2021-11-11 14:04:571697瀏覽

這篇文章要為大家介紹mysql-8.0 的一些簡單的配置,希望對大家有幫助!

mysql-8.0 一些簡單的設定

#下載

下載後,將zip解壓縮後放到一個目錄下,配置好環境變數

設定檔

下載好後,下載的根目錄沒有my.ini 檔(或my-default.ini),沒有my. ini文件,沒關係可以自行建立。在安裝根目錄下新增 my.ini

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=C:\Program Files\mysql-8.0.12-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\mysql\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
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

注意,裡面的 basedir 是我本地的安裝目錄,datadir 是我資料庫資料檔案要存放的位置,各項設定需要依照自己的環境進行設定。

初始化資料庫

在MySQL安裝目錄的bin 目錄下執行指令:

mysqld --initialize --console

執行完成後,會列印root 使用者的初始預設密碼

C:\Program Files\mysql-8.0.12-winx64\bin
λ mysqld --initialize --console
2018-07-28T08:09:39.819831Z 0 [System] [MY-013169] [Server] C:\Program Files\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 8624
2018-07-28T08:09:46.120948Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: thbVf;1w7(Zy
2018-07-28T08:09:48.278535Z 0 [System] [MY-013170] [Server] C:\Program Files\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server has completed

thbVf;1w7(Zy就是初始密碼(不含首位空格)

如果刪掉初始化的datadir 目錄,再執行一遍初始化指令,又會重新產生的

安裝服務

在MySQL安裝目錄的bin目錄下執行指令(以管理員身分開啟cmd命令列)

mysqld --install [服务名]

後面的服務名稱可以不寫,預設的名字是mysql。當然,如果你的電腦上需要安裝多個MySQL服務,就可以用不同的名字區分了,例如mysql5 和mysql8。

安裝完成之後,就可以透過指令net start mysql啟動MySQL的服務了。

C:\Program Files\mysql-8.0.12-winx64\bin
λ mysqld --install
Service successfully installed.
C:\Program Files\mysql-8.0.12-winx64\bin
λ net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

更改密碼

在MySQL安裝目錄的bin 目錄下執行指令: mysql -u root -p

  這時候會提示輸入密碼,剛剛的初始密碼進去後:修改密碼如下代碼

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

結果

C:\Program Files\mysql-8.0.12-winx64\bin
λ 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.12
Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.08 sec)
mysql> exit

推薦學習:《mysql視頻教程

以上是講解mysql8.0的部分簡單配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:juejin.im。如有侵權,請聯絡admin@php.cn刪除