ubuntu mysql 安裝和使用者登入

2021-06-06 15:18:21 字數 2298 閱讀 1572

要安裝 mysql,可以在終端提示符後執行下列命令:

sudo apt-get install mysql-server mysql-client #中途會讓你輸入一次root使用者密碼
sudo apt-get install php5-mysql  #安裝php5-mysql 是將php和mysql連線起來
一旦安裝完成,mysql 伺服器應該自動啟動。

sudo start mysql #手動的話這樣啟動
sudo stop mysql #手動停止
當你修改了配置檔案後,你需要重啟 mysqld 才能使這些修改生效。

要想檢查 mysqld 程序是否已經開啟,可以使用下面的命令:

pgrep mysqld
如果程序開啟,這個命令將會返回該程序的 id。

ps -a|grep mysql

如果存在mysqld,mysqld_safe等程序的話,則會顯示出來,如:

4460 pts/0    00:00:00 mysqld_safe

4583 pts/0    00:00:01 mysqld

登入mysql問題:

(1)mysql -u root -p

輸入密碼之後,錯誤提示如下:error 1045 (28000): access denied for user 'root'@'localhost' (using password: yes),意思是root的密碼不正確。

解決辦法如下:

a.sudo mysqld_safe --user=root --skip-grant-tables --skip-networking &

輸入命令之後,提示資訊如下:

[1] 5166

root@jungsagacity:/home/jung# 120521 18:46:32 mysqld_safe logging to syslog.

120521 18:46:32 mysqld_safe starting mysqld daemon with databases from /var/lib/mysql

如果提示資訊為:

[2] 4928

root@jungsagacity:/home/jung# 120521 18:44:40 mysqld_safe logging to syslog.

120521 18:44:40 mysqld_safe a mysqld process already exists

表示mysqld_safe程序存在,可以通過

ps -a|grep mysql 檢視mysqld_safe程序id

kill -9 -***x            終結id為***x的程序

下面繼續輸入命令:

mysql -u root mysql     表示以root使用者登入到mysql資料庫當中

select * from user;        可以看到登記的使用者名稱和密碼等詳細資訊。此時會看到root 對應的密碼是 123456.

實際上我們輸入

mysql -u root -p 

enter password: 123456

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

重新修改root密碼:

update user set password=password('123456') where user='root' and host='localhost';

flush privileges;      這一句話必須的輸入,否則退出mysql客戶端之後,依然登入不了。

(2)新建使用者無法登入

以root使用者身份登入到資料庫mysql之後之後,可以新建乙個本地的使用者jun,退出客戶端之後,以jun進行登入,出現錯誤資訊

error 1045 (28000): access denied for user 'wujun'@'localhost' (using password: yes)

出現這個錯誤主要有以下亮點錯誤:

a.新建使用者的時候,密碼以字串'******'的形式輸入,而不是以password('******')形式輸入

正確的語句:

mysql> insert into user(host,user,password) values('local',jun,password('******'));

mysql> flush privileges;

b.正確的輸入插入語句之後,但沒有輸入

mysql> flush privileges;

ubuntu MySQL安裝指南

安裝 mysql,可以在終端提示符後執行下列命令 sudo apt get install mysql server sudo apt get install mysql client sudo apt get install php5 mysql 安裝php5 mysql 是將php和mysql連...

ubuntu MySQL安裝指南

要安裝 mysql,可以在終端提示符後執行下列命令 sudo apt get install mysql server sudo apt get install mysql client sudo apt get install php5 mysql 安裝php5 mysql 是將php和mysql...

Ubuntu MySQL安裝指南

安裝mysql sudo apt get install mysql server 這個應該很簡單了,而且我覺得大家在安裝方面也沒什麼太大問題,所以也就不多說了,下面我們來講講配置。配置mysql 注意,在ubuntu下mysql預設是只允許本地訪問的,如果你要其他機器也能夠訪問的話,那麼需要改變 ...