linux安裝mysql yum版本

二、卸載掉原有mysql

因爲mysql數據庫在Linux上實在是太流行了,所以目前下載的主流Linux系統版本基本上都集成了mysql數據庫在裏面,我們可以通過如下命令來查看我們的操作系統上是否已經安裝了mysql數據庫

[root@xiaoluo ~]# rpm -qa | grep mysql  // 這個命令就會查看該操作系統上是否已經安裝了mysql數據庫

有的話,我們就通過 rpm -e 命令 或者 rpm -e --nodeps 命令來卸載掉

[root@xiaoluo ~]# rpm -e mysql  // 普通刪除模式
[root@xiaoluo ~]# rpm -e --nodeps mysql  // 強力刪除模式,如果使用上面命令刪除時,提示有依賴的其它文件,則用該命令可以對其進行強力刪除

在刪除完以後我們可以通過 rpm -qa | grep mysql 命令來查看mysql是否已經卸載成功!!

我是通過yum的方式來進行mysql的數據庫安裝,首先我們可以輸入 yum list | grep mysql 命令來查看yum上提供的mysql數據庫可下載的版本:

[root@xiaoluo ~]# yum list | grep mysql

就可以得到yum服務器上mysql數據庫的可下載版本信息:

 

 

然後我們可以通過輸入 yum install -y mysql-server mysql mysql-devel 命令將mysql mysql-server mysql-devel都安裝好(注意:安裝mysql時我們並不是安裝了mysql客戶端就相當於安裝好了mysql數據庫了,我們還需要安裝mysql-server服務端才行)

 

[root@xiaoluo ~]# yum install -y mysql-server mysql mysql-deve

 

在等待了一番時間後,yum會幫我們選擇好安裝mysql數據庫所需要的軟件以及其它附屬的一些軟件

 

 

我們發現,通過yum方式安裝mysql數據庫省去了很多沒必要的麻煩,當出現下面的結果時,就代表mysql數據庫安裝成功了

 

 

此時我們可以通過如下命令,查看剛安裝好的mysql-server的版本

 

[root@xiaoluo ~]# rpm -qi mysql-server

 

我們安裝的mysql-server並不是最新版本,如果你想嘗試最新版本,那就去mysql官網下載rpm包安裝就行了,至此我們的mysql數據庫已經安裝完成了。

四、mysql數據庫的初始化及相關配置

我們在安裝完mysql數據庫以後,會發現會多出一個mysqld的服務,這個就是咱們的數據庫服務,我們通過輸入 service mysqld start 命令就可以啓動我們的mysql服務。

注意:如果我們是第一次啓動mysql服務,mysql服務器首先會進行初始化的配置,如:

複製代碼
[root@xiaoluo ~]# service mysqld start

初始化 MySQL 數據庫: WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h xiaoluo password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [確定]
正在啓動 mysqld:                                            [確定]
複製代碼

 

這時我們會看到第一次啓動mysql服務器以後會提示非常多的信息,目的就是對mysql數據庫進行初始化操作,當我們再次重新啓動mysql服務時,就不會提示這麼多信息了,如:

 

[root@xiaoluo ~]# service mysqld restart
停止 mysqld:                                             [確定]
正在啓動 mysqld:                                          [確定]

 

我們在使用mysql數據庫時,都得首先啓動mysqld服務,我們可以 通過  chkconfig --list | grep mysqld 命令來查看mysql服務是不是開機自動啓動,如:

 

[root@xiaoluo ~]# chkconfig --list | grep mysqld
mysqld             0:關閉    1:關閉    2:關閉    3:關閉    4:關閉    5:關閉    6:關閉

 

我們發現mysqld服務並沒有開機自動啓動,我們當然可以通過 chkconfig mysqld on 命令來將其設置成開機啓動,這樣就不用每次都去手動啓動了

 

[root@xiaoluo ~]# chkconfig mysqld on
[root@xiaoluo ~]# chkconfig --list | grep mysql
mysqld             0:關閉    1:關閉    2:啓用    3:啓用    4:啓用    5:啓用    6:關閉

 

mysql數據庫安裝完以後只會有一個root管理員賬號,但是此時的root賬號還並沒有爲其設置密碼,在第一次啓動mysql服務時,會進行數據庫的一些初始化工作,在輸出的一大串信息中,我們看到有這樣一行信息 :

 

/usr/bin/mysqladmin -u root password 'new-password'  // 爲root賬號設置密碼

 

所以我們可以通過 該命令來給我們的root賬號設置密碼(注意這個root賬號是mysql的root賬號,非Linux的root賬號)

 

[root@xiaoluo ~]# mysqladmin -u root password 'root'  // 通過該命令給root賬號設置密碼爲 root

 

此時我們就可以通過 mysql -u root -p 命令來登錄我們的mysql數據庫了


一、MySQL登錄錯誤

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'

無法修改密碼

用 service mysqld stop

mysqld_safe --skip-grant-tables &

輸入 mysql -uroot -p 回車進入

>use mysql;

> update user set password=PASSWORD("newpass")where user="root";
 更改密碼爲 newpassord

> flush privileges; 更新權限

> quit 退出

 



service mysqld restart

mysql -uroot -p新密碼進入

 

===========================================================

二,忘記本地root的登錄密碼

解決過程:

1、編輯/etc/my.cnf

在[mysqld] 配置部分添加一行

skip-grant-tables
 

2、保存後重啓mysql

[root@localhost etc]# service mysqld restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL.                                                   [  OK  ]

3、登錄數據庫重新設置root密碼


[root@localhost ~]# mysql -uroot -p mysql
Enter password:

直接回車進入


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.47-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)


執行下列語句

mysql> update user set password=password("mysql") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 

4、刪除/etc/my.cnf文件中添加的“skip-grant-tables”行,重啓mysql;

用新設的密碼就能正常登錄了;


 下面我們另外添加一個新的 root 用戶, 密碼爲password, 只允許 192.168.1.100 連接

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY 'password' WITH GRANT OPTION;
 flush privileges;
'192.168.1.100'可以替換爲@‘%’就可任意ip訪問,

導入大型CSV文件
load data local infile '/home/hadoop/JData_Action_201602.csv' into table  JData_Action_201602  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' lines terminated by '\n' ignore 1 lines (user_id,sku_id,time,model_id,type,cate,brand);  

發佈了55 篇原創文章 · 獲贊 3 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章