mysql研究方向 MySQL 常用

2021-10-18 11:48:38 字數 2531 閱讀 4652

mysql 段錯誤

現象:在登陸或者執行命令時,提示 「段錯誤」並直接退出mysql

問題原因:

資料庫和你的伺服器的編碼不一致導致的。

最初的時候linux伺服器的編碼方式是utf-8,windows編碼方式為gbk,為了讓兩者編碼方式一直,我們通常會將linux伺服器的編碼設定為gbk。這個時候上面的問題就產生了,因為mysql使用的編碼還是utf-8,而伺服器的編碼已經修改為gbk,兩者編碼不一致,導致上面的段錯誤。

解決方法:

修改字符集,具體檢視以及修改不同級別字符集的方法,參見下面鏈結

另外,一般可能是中英文字符集不匹配,臨時應對,可以 export lang=en_us

mysql 登陸

mysql -u root -p

一、連線遠端資料庫:

1、顯示密碼

如:mysql 連線遠端資料庫(192.168.5.116),埠「3306」,使用者名為「root」,密碼「123456」

c:/>mysql -h 192.168.5.116 -p 3306 -u root -p123456

2、隱藏密碼

如:mysql 連線本地資料庫,使用者名為「root」,

c:/>mysql -h localhost -u root -p

enter password:

二、配置mysql允許遠端鏈結

預設情況下,mysql帳號不允許從遠端登陸,只能在localhost登入。本文提供了二種方法設定mysql可以通過遠端主機進行連線。

一、改表法

在localhost登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,將"localhost"改稱"%"

例如:#mysql -u root -p

enter password:

mysql>

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

二、授權法

例如: 你想myuser使用mypassword(密碼)從任何主機連線到mysql伺服器的話。

mysql>grant all privileges on *.* to 'myuser'@'%'identified by 'mypassword' with grant option;

如果你想允許使用者myuser從ip為192.168.1.6的主機連線到mysql伺服器,並使用mypassword作為密碼

mysql>grant all privileges on *.* to 'myuser'@'192.168.1.3'identified by

'mypassword' with grant option;

mysql>flush privileges

使修改生效,就可以了

常見問題:

1、在採用法二授權法之後,無法在本地登入mysql(如:#mysql -u root -p -h 192.168.5.116

enter password:

error 1045 (28000): access denied for user 'root'@'loadb116' (using password: yes)

上例中loadb116是主機名.

解決方法:

1、這時可以使用:mysql  -u root -p 登入,進入到mysql後。

mysql> grant all privileges on *.* to 'root'@'loadb116'

identified by '123456' with grant option;

query ok, 0 rows affected (0.00 sec)

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

2、在本地使用ip位址登入

# mysql -u root -p -h 192.168.5.116

enter password:

welcome to the mysql monitor.  commands end with ; or /g.

your mysql connection id is 60

server version: 5.1.45 mysql community server (gpl)

type 'help;' or '/h' for help. type '/c' to clear the buffer.

mysql>

mysql 大小寫

資料庫名稱大小寫不敏感,截圖如下:

mysql> create databasegg;

query ok,1 row affected (0.00sec)

mysql> create databasegg;

error1007 (hy000): can't create database'gg'; database exists

mysql>

資料庫表名稱不敏感,欄位名稱不敏感

mysql常問內容 mysql常問問題

前言 一些自己遇到的問題及理解 需補充修改 索引型別 主鍵索引 普通索引 符合索引 唯一索引 全文索引 索引 查詢資料的資料結構,索引占用磁碟空間,更新資料的時候影響更新表的效率 資料儲存型別 聚簇索引 非聚簇索引 聚簇 採用b 樹的資料結構,聚簇索引葉子節點存放證章表的資料,所以主鍵索引就是用的聚...

mysql檢視mylog命令 mysql常用命令

連線mysql 1.登入mysql資料庫 mysql u使用者名稱 p密碼 示例 2.登入遠端主機的mysql mysql h遠端主機ip位址 u使用者名稱 p密碼 示例 注 建立使用者命令格式為 create user hehe 192.168.93.151 3.退出mysql命令 exit 修改...

mysql execute指令 mysql常用命令

一 游標 游標 cursor 是處理資料的一種方法,為了檢視或者處理結果集中的資料,游標提供了在結果集中一次一行或者多行前進或向後瀏覽資料的能力。可以把游標當作乙個指標,它可以指定結果中的任何位置,然後允許使用者對指定位置的資料進行處理。模版案例一 import if name main cnx c...