在Linux系統下安裝MySQL,有時候可能會出現沒有配置文件的情況。這時候我們需要手動創建并配置配置文件。
以下步驟是基于Ubuntu系統的安裝方法,請根據自己的系統進行對應操作。
1. 安裝MySQL sudo apt-get install mysql-server 2. 檢查是否安裝成功 sudo service mysql status 3. 創建配置文件 sudo touch /etc/mysql/my.cnf 4. 使用編輯器打開my.cnf sudo vi /etc/mysql/my.cnf 5. 將下列代碼粘貼至文件中 [client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp skip-external-locking bind-address = 127.0.0.1 key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam-recover = BACKUP query_cache_limit = 1M query_cache_size = 16M log_error = /var/log/mysql/error.log [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M !includedir /etc/mysql/conf.d/ 6. 保存文件并重啟MySQL服務 sudo service mysql restart
經過以上步驟,你就成功地創建了MySQL配置文件,并且完成了配置。接下來,你可以愉快地使用MySQL了!