MYSQL 允許遠端訪問

2021-07-22 17:01:38 字數 2267 閱讀 4081

本文詳細介紹ubuntu下mysql資料庫安裝後初步設定。

1、安裝mysql 這個應該很簡單了,而且我覺得大家在安裝方面也沒什麼太大問題,所以也就不多說了,下面我們來講講配置。

2、配置mysql 注意,在ubuntu下mysql預設是只允許本地訪問的,如果你要其他機器也能夠訪問的話,那麼需要改變/etc/mysql/my.cnf配置檔案了!

預設的mysql安裝之後根使用者是沒有密碼的,所以首先用根使用者進入: $mysql -u root 在這裡之所以用-u root是因為我現在是一般使用者(firehare),如果 不加-u root的話,mysql會以為是firehare在登入。

注意,我在這裡沒有進入根使用者模式,因為沒必要。一般來說,對mysql中的資料庫進行操作,根本沒必要進入根使用者模式,只有在設定時才有這種可能。進入mysql之後,最要緊的就是要設定mysql中的root使用者密碼了,否則,mysql服務無安全可言了。

mysql> grant all privileges on *.* to root@localhost identified by "123456";

注意,我這兒用的是123456做為root使用者的密碼,但是該密碼是不安全的,請大家最好使用大小寫字母與數字混合的密碼,且不少於8位。這樣的話,就設定好了mysql中的root使用者密碼了,然後就用root使用者建立你所需要的資料庫。

我這裡就以xoops為例:

mysql>create database xoops; mysql>

grant all privileges on xoops.* to xoops_root@localhost identified by "654321";

這樣就建立了乙個xoops_roots的使用者,它對資料庫xoops有著全部許可權。以後就用xoops_root來對xoops資料庫進行管理,而無需要再用root使用者了,而該使用者的許可權也只被限定在xoops資料庫中。

如果你想進行遠端訪問或控制,那麼你要做兩件事:

其一:mysql>grant all privileges on xoops.* to xoops_root@"%" identified by "654321";

允許xoops_root使用者可以從任意機器上登入mysql。

其二:$sudo gedit /etc/mysql/my.cnf >skip-networking => # skip-networking

這樣就可以允許其他機器訪問mysql了。

在ubuntu下連線資料庫的gui軟體:mysql-admin mysql-query-browser。

一:匯出資料:

mysqldump -uroot -p --default-character-set

=latin1 --set-charset=gbk --skip-opt mydatabse > d.sql

二:建立新的資料庫:

create database `newmydatabase` default

character set gbk collate gbk_chinese_ci;

三:重新匯入資料:

mysql -uroot -p --default-character-set=

gbk -f newmydatabase >source d.sql ..... >exit

1.在終端啟動:mysql -uroot -p密碼 然後回車;

2.檢視資料庫的名字:show databases;;

3.選擇乙個資料庫:use test_stinfo;;(今天總是select,慚愧。)

4.檢視已選擇資料庫中表的名字:show tables;;

5.檢視表的詳細情況:desc t_teacher;;

6.建立乙個資料庫:create database test_51cto;;

7.(use test_51cto)建立表:create table test_table(51ctoid int(8)primary ket not null,

51ctoname varchar(20)not null);;

8.修改表(增加列):alter table test_table add 51ctoscore int(8) not null;;

9.修改表(修改列):alter table test_table modify 51ctoscore double(8,1) not null;;

10.修改表(刪除列):alter table test_table drop 51ctoscore;;

11.刪除乙個資料庫:drop database test_51cto;;

12.退出mysql:exit

mysql允許遠端IP訪問

預設情況下linux內的mysql資料庫mysql,user表內的使用者許可權只是對localhost即本機才能登陸。需要更改許可權 mysql grant all privileges on to root identified by password with grant option 表示是所...

mysql 允許遠端主機訪問

登入mysql後,更改 mysql 資料庫裡的 user 表裡的 host 項,從 localhost 改稱 mysql u root pvmwaremysql use mysql mysql update user set host where user root mysql select hos...

Mysql授權允許遠端訪問

mysql community edition gpl 在我們使用mysql資料庫時,有時我們的程式與資料庫不在同一機器上,這時我們需要遠端訪問資料庫。預設狀態下,mysql的使用者是沒有遠端訪問的許可權。下面介紹兩種方法,解決這一使用者遠端訪問的許可權問題。1 改表法 可能是你的帳號不允許從遠端登...