MySQL配置my.ini文件全過程
my.ini文件中存儲了數(shù)據(jù)庫的文件地址,數(shù)據(jù)庫數(shù)據(jù)存儲地址以及登錄密碼等基礎信息。
在遇到忘記密碼或者其他基礎問題時,修改my.ini文件很方便。但是部分數(shù)據(jù)庫版本默認不生成my.ini文件,需要自己進行配置。
1.停止數(shù)據(jù)庫服務
在搜索框中輸入cmd,選擇以管理員身份打開。輸入
sc delete mysql(注意,這里的mysql是你的數(shù)據(jù)庫服務名稱,不知道怎么看的win+R后輸入services.msc回車,就能在名稱那一列找到你的mysql名稱)
回車
顯示成功后在管理(win+R回車后輸入services.msc,回車)里看一下,如果數(shù)據(jù)庫在管理中仍然存在,右鍵選擇停止。數(shù)據(jù)庫在管理中消失。
2.新建my.ini配置文件
配置文件存放路徑如下圖:

我的mysql目錄下不允許生成新文件,所以我在別的地方新建my.ini,編輯好后直接復制到存放的目錄下。
下列代碼復制到my.ini中
# 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. [client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_bin init_connect=‘SET NAMES utf8mb4' # 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. basedir = datadir = port = 3306 # server_id = … # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. join_buffer_size = 128M sort_buffer_size = 16M read_rnd_buffer_size = 16M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
其中basedir datadir是自己的數(shù)據(jù)庫和數(shù)據(jù)庫數(shù)據(jù)存放路徑。路徑記得刪雙引號
3.刪除data文件夾
有重要數(shù)據(jù)提前備份!
還是管理員身份打開cmd
mysqld --initialize-insecure --user=mysql
輸入命令回車后系統(tǒng)會自動生成data文件夾
4.配置my.ini
mysqld --install “給自己的mysql命名” --defaults-file=“my.ini的路徑”
建議不要把mysql的名字取得花里胡哨的,也別出現(xiàn)中文,最多就換兩個大小寫,加點數(shù)字區(qū)分版本號就行了。
5.重啟mysql,自定密碼
5.1管理員打開cmd,輸入
net start mysql(這里的mysql是你剛才定義的數(shù)據(jù)庫名稱)
回車后會顯示你的數(shù)據(jù)庫啟動成功
5.2輸入
mysql -u root -p
顯示輸入密碼不用管,直接回車就可以進入mysql
5.3輸入
ALTER USER ‘root'@‘localhost' IDENTIFIED WITH mysql_native_password BY ‘自定義密碼';
注意:
- 1.這是mysql8.0以上的語句,如果是8.0一下,要自己搜一下。
- 2.建議把密碼記好,不然不記得密碼了,重置又是一個坎
5.4輸入
quit;
退出mysql
6.測試
打開一個普通的cmd,輸入
mysql -uroot -p
回車后輸入密碼,顯示進入mysql即為成功。
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
本文深入淺出的分析了如何給千萬級mysql快速分頁做優(yōu)化,非常的實用,是篇不可多得的文章,程序員必讀?。?/div> 2014-09-09
從云數(shù)據(jù)遷移服務看MySQL大表抽取模式的原理解析
這篇文章主要介紹了從云數(shù)據(jù)遷移服務看MySQL大表抽取模式的原理解析,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02最新評論

