## 一、Ignoring query to other database 提示錯誤
在成功登錄 mysql 后,輸入任意一條命令都會出 `Ignoring query to other database ` 這條提示信息:
```sql
mysql> show databases;
Ignoring query to other database
mysql> show databases;
Ignoring query to other database
mysql> show tables;
Ignoring query to other database
```
### 1.出現這條提示信息原因一般是因為登錄時由于疏忽少了一個 `-u` 的參數:
```sql
root@dawsson~:~# mysql -root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 63842
Server version: 5.7.25-0ubuntu0.16.04.2 (Ubuntu)
...
```
退出后使用 `mysql -uroot -p` 重新登錄即可。
### 2.或者在登錄時使用的大寫的 `-U` 參數:
```sql
root@dawsson~:~# mysql -Uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 63844
Server version: 5.7.25-0ubuntu0.16.04.2 (Ubuntu)
...
mysql> show databases;
Ignoring query to other database
mysql> show tables;
Ignoring query to other database
```
大寫 U 和小寫 u 這兩個參數的含義是不一樣的。查看 mysql 的幫助:
```sql
root@dawsson~:~# mysql --help| egrep 'user|safe-updates'
-u, --user=name User for login if not current user.
-U, --safe-updates Only allow UPDATE and DELETE that uses keys.
-U, --i-am-a-dummy Synonym for option --safe-updates, -U.
--select-limit=# Automatic limit for SELECT when using --safe-updates.
--safe-updates.
user (No default value)
safe-updates FALSE
root@dawsson~:~#
```
可以發現,小寫的 `-u` 用于正常的用戶登錄;大寫的 `-U` 用于用戶使用 **“安全更新”** 的身份登錄,此時只能進行 update 和 delete 的操作,且必須加條件 where(其中 where 子句必須有索引列) 或 limit 才能執行。(前提是 數據庫已開啟安全更新的模式,即設置 `sql_safe_updates = 1`)