ubuntu上安裝mysql非常簡單只需要幾條命令就可以完成。
1. sudo apt-get install mysql-server
2. apt-get isntall mysql-client
3. sudo apt-get install libmysqlclient-dev
安裝過程中會提示設定密碼什麼的,注意設定了不要忘了,安裝完成之後可以使用如下命令來檢查是否安裝成功:
sudo netstat -tap | grep mysql
通過上述命令檢查之後,如果看到有mysql 的socket處於 listen 狀態則表示安裝成功。
登陸mysql資料庫可以通過如下命令:
mysql -u root -p
-u 表示選擇登陸的使用者名稱, -p 表示登陸的使用者密碼,上面命令輸入之後會提示輸入密碼,此時輸入密碼就可以登入到mysql。
然後通過show databases; 就可以檢視當前的資料庫。
寫乙個簡單的程式來訪問該資料庫,實現 show tables 功能:
#include #include #include int main()g++ -wall mysql_test.cpp -o mysql_test-lmsqlclient然後執行編譯好的**:if (mysql_query(conn, "show tables"))
res = mysql_use_result(conn);
printf("mysql tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != null)
mysql_free_result(res);
mysql_close(conn);
printf("finish! \n");
return 0;
}
可見結果和使用sql語句 show tables 是一樣的。
報錯:1130-host...isnotallowedtoconnecttothismysqlserver
解決方法:
1。 改表法。
可能是你的帳號不允許從遠端登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,從"localhost"改稱"%"
mysql-u root -pvmwaremysql>usemysql;
mysql>update user sethost= '%' where user = 'root';
mysql>selecthost, user from user;
2. 授權法。
例如,你想myuser使用mypassword從任何主機連線到mysql伺服器的話。
grant all privileges on *.*to'myuser'@'%' identified by 'mypassword' with grant option;
flush privileges;
如果你想允許使用者myuser從ip為192.168.1.6的主機連線到mysql伺服器,並使用mypassword作為密碼
grant all privileges on *.*to'myuser'@'192.168.1.3' identified by 'mypassword' with grant option;
flush privileges;
如果你想允許使用者myuser從ip為192.168.1.6的主機連線到mysql伺服器的dk資料庫,並使用mypassword作為密碼
grant all privileges on dk.*to'myuser'@'192.168.1.3' identified by 'mypassword' with grant option;
flush privileges;
我用的第乙個方法,剛開始發現不行,在網上查了一下,少執行乙個語句mysql>flush rivileges 使修改生效.就可以了
另外一種方法,不過我沒有親自試過的,在csdn.net上找的,可以看一下.
在安裝mysql的機器上執行:
1、d:\mysql\bin\>mysql-h localhost -u root //這樣應該可以進入mysql伺服器
2、mysql>grant all privileges on *.*to'root'@'%' with grant option //賦予任何主機訪問資料的許可權
3、mysql>flush privileges //修改生效
4、mysql>exit //退出mysql伺服器
這樣就可以在其它任何的主機上以root身份登入啦!
ubuntu下 libevent庫安裝和簡單測試
解壓縮 tar zxvf libevent 2.1.8 stable.tar.gz cd libevent 2.1.8 stable 依次輸入 configure prefix usr 配置目錄 make sudo make install 檢視是否安裝成功 ls l usr lib grep li...
Ubuntu 上安裝MYSQL資料庫以及簡單操作
在ubuntu上安裝mysql是一件很簡單的事情,只需要幾條命令就可以了 1 首選按裝一下vim工具的命令 sudo apt get install vim gtk 這裡注意一下,可能會出現一下錯誤 e 無法獲得鎖 var lib dpkg lock open 11 資源暫時不可用 e 無法鎖定管理...
ubuntu 安裝和配置mysql
1 安裝,sudo apt get install mysql server輸入超級使用者密碼,就會自動安裝了,中間會詢問root使用者的密碼。2 給使用者設定許可權和密碼,如grant select,insert,update,delete on to user1 localhost identi...