使用〜/ .my.cnf更改默认的mysql存储引擎

时间:2014-12-12 19:04:27

标签: mysql myisam my.cnf

我正在使用MySQL 5.5并尝试仅为自己更改默认存储引擎。我尝试按照我在此处找到的说明在我的主目录中创建.my.cnf文件:

http://dev.mysql.com/doc/refman/5.5/en/storage-engine-setting.html

http://dev.mysql.com/doc/refman/5.5/en/option-files.html

你可以看到我到目前为止所做的更改:

selah@selah-OptiPlex-9020:~$ cat .my.cnf
[mysqld]
default-storage-engine=MyISAM
selah@selah-OptiPlex-9020:~$ sudo /etc/init.d/mysql restart
[sudo] password for selah: 
 * Stopping MySQL database server mysqld                                                                                                  [ OK ] 
 * Starting MySQL database server mysqld                                                                                                  [ OK ] 
 * Checking for tables which need an upgrade, are corrupt or were 
not closed cleanly.

然而,MyISAM仍然不是默认值!

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

如何让它发挥作用?

编辑:为了记录,我只能通过编辑我的/etc/mysql/my.cnf文件并重新启动我的计算机来完成这项工作(只需重新启动该过程失败)。但是,我仍然想了解如何仅为我的用户更改此内容!

1 个答案:

答案 0 :(得分:0)

default_storage_engine是服务器设置,而不是连接设置。 mysqld服务器不会读取您的用户'〜/ .my.cnf',而客户只能阅读[client]部分,而不是[mysqld]部分。

您可以通过'〜/ .my.cnf'中init-commend部分的[client]进行更改:

init-command="SET default_storage_engine=MYISAM;"