mysql bingip,MySQL报错Ignoring query to other database的真正原因
大家都知道報這個錯的原因是忘了用戶名前加-u這個參數(shù)造成的,比如是這樣登錄了MySQL
# mysql -root -p (注意看,-root前面沒有加u)
登錄后,不管你執(zhí)行什么命令,都會提示Ignoring query to other database
mysql>show databases;
Ignoring query to other database
要解決這個問題,我們只要加上-u這個參數(shù)就可以了。
# mysql –uroot -p
網(wǎng)上很多都寫到這里為止了,但并沒有去分析為什么沒有加-u也能登錄成功,為什么登錄成功后執(zhí)行sql語句會報錯。
這里我就給大家分析一下為什么會這樣的真正原因。
這是因為當(dāng)執(zhí)行 “mysql -root -p ”這個不帶有-u的命令時,mysql命令把-root識別成了它的參數(shù),而不是root這個用戶。并且把root這個詞識別成了四個參數(shù),拆開來就是“-r -o -o -t”。
當(dāng)不帶有-u參數(shù)時,默認(rèn)就是以root用戶登錄的。
所以當(dāng)沒有帶-u參數(shù)時,整個命令其實是這樣的:
#mysql -r -o -o -t -p -uroot //其中-uroot是隱式帶上的
所以雖然沒有帶上-u參數(shù),是可以登錄成功的,而登錄成功后,報錯,是因為有-o這個參數(shù)造成的。
我們看看-o這個參數(shù)的解釋:
-o,–one-database
Ignore statements except those that occur while the default database is the one named on the command line. This option is rudimentary and should be used with care. Statement filtering is based only on USE statements.
翻譯過來就是,當(dāng)帶上-o參數(shù)時,會忽略sql語句,但如果在-o參數(shù)后面帶上某數(shù)據(jù)庫名,這個數(shù)據(jù)庫可以排除在外,也就是這個數(shù)據(jù)庫可以執(zhí)行sql語句。
比如我們想登錄數(shù)據(jù)庫后,只能在mysql這個數(shù)據(jù)庫執(zhí)行命令sql命令,在其它數(shù)據(jù)庫中都執(zhí)行不了sql命令
# mysql -o mysql -p
mysql> use test
Database changed
mysql> show tables;
Ignoring query to other database
mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
mysql> select * from test.test1;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
mysql> use test
Database changed
mysql> select * from mysql.user;
Ignoring query to other database
mysql>
可以看出,當(dāng)使用use切換到mysql數(shù)據(jù)庫,就可以執(zhí)行sql命令,當(dāng)使用use切換到別的數(shù)據(jù)庫下,就執(zhí)行不了,會報錯。
知道這個-o參數(shù)的作用后,我們就知道為什么前面登錄后執(zhí)行命令會報錯了。
總結(jié)
以上是生活随笔為你收集整理的mysql bingip,MySQL报错Ignoring query to other database的真正原因的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab中画花瓣,matlab画心,
- 下一篇: matlab正弦序列频谱,【求助】正弦信