1. 程式人生 > >linux下安裝mysql(rpm檔案安裝)

linux下安裝mysql(rpm檔案安裝)

資料庫包下載:

https://www.mysql.com/downloads/

在GPL開原協議的社群開源版裡邊下載

 

 

我們用mysql community server裡邊的

 

 

 

 

其中workbench是客戶端工具

 

 

MySQL Cluster是oracle自己搞的叢集版的(集成了一些開源工具和增值服務)

 

 

 

選擇作業系統和版本

建議在linux下安裝

 

 

也可以選擇版本

 

 

下載server包和client包

如果是server包,那架構圖裡的東西都有了

還要下個client utilities包,客戶端包,類似connection層

 

 

 

 

下載後用rz命令傳到centos linux系統裡邊

rpm是包管理器

xshell可以直接拖

也可以用rz命令,沒有的話安裝一下: yum install lrzsz

yum是包資源管理器,可以解決包依賴的問題,把需要的包都下載下來

傳到linux系統

 

 

安裝mysql步驟:

清理環境

centos7會自帶一個mariadb

檢視是否已安裝

rpm -qa |grep -i mysql

rpm -qa |grep -i mariadb(centos7預設系統自帶的)

 

mariadb是從mysql來的,是它的一個分支,需要清理掉

清理掉mariadb包

用yum直接安裝你的話,用的mariadb的yum源,它跟mysql官方正式版不太一樣,我們要安裝官方正式版,就需要清掉mariadb,然後手動安裝自己下載的官方正式版mysql

rpm -e 加上包名,把mariadb包清掉

可以看到用rpm刪除會失敗,提示有依賴關係的軟體需要安裝

rpm -e mariadb-libs-5.5.56-2.el7.x86_64

 

rpm刪除時如果有依賴關係,可以用yum remove + 包名來刪除mariadb

 

開始安裝:

一般用裝軟體用yum直接安裝也可以,但是有一個問題:用yum的話,是到預設的mariadb用的yum源去找,可能會找不到,所以我們自己來安裝

 

rpm –ivh + 包安裝所需要的包

rpm -ivh MySQL-client-5.6.42-1.el7.x86_64.rpm

 

 

rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm

 

 

server安裝成功後會輸出一些資訊,如下:

[[email protected] soft]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm

warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing...                          ################################# [100%]

Updating / installing...

   1:MySQL-server-5.6.42-1.el7        ################################# [100%]

warning: user mysql does not exist - using root

warning: group mysql does not exist - using root

warning: user mysql does not exist - using root

warning: group mysql does not exist - using root

2018-11-18 13:53:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-11-18 13:53:24 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

2018-11-18 13:53:24 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 6420 ...

2018-11-18 13:53:24 6420 [Note] InnoDB: Using atomics to ref count buffer pool pages

2018-11-18 13:53:24 6420 [Note] InnoDB: The InnoDB memory heap is disabled

2018-11-18 13:53:24 6420 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2018-11-18 13:53:24 6420 [Note] InnoDB: Memory barrier is not used

2018-11-18 13:53:24 6420 [Note] InnoDB: Compressed tables use zlib 1.2.11

2018-11-18 13:53:24 6420 [Note] InnoDB: Using Linux native AIO

2018-11-18 13:53:24 6420 [Note] InnoDB: Using CPU crc32 instructions

2018-11-18 13:53:24 6420 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2018-11-18 13:53:24 6420 [Note] InnoDB: Completed initialization of buffer pool

2018-11-18 13:53:24 6420 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

2018-11-18 13:53:24 6420 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

2018-11-18 13:53:24 6420 [Note] InnoDB: Database physically writes the file full: wait...

2018-11-18 13:53:24 6420 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

2018-11-18 13:53:25 6420 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB

2018-11-18 13:53:25 6420 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0

2018-11-18 13:53:25 6420 [Warning] InnoDB: New log files created, LSN=45781

2018-11-18 13:53:25 6420 [Note] InnoDB: Doublewrite buffer not found: creating new

2018-11-18 13:53:25 6420 [Note] InnoDB: Doublewrite buffer created

2018-11-18 13:53:25 6420 [Note] InnoDB: 128 rollback segment(s) are active.

2018-11-18 13:53:25 6420 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-11-18 13:53:25 6420 [Note] InnoDB: Foreign key constraint system tables created

2018-11-18 13:53:25 6420 [Note] InnoDB: Creating tablespace and datafile system tables.

2018-11-18 13:53:25 6420 [Note] InnoDB: Tablespace and datafile system tables created.

2018-11-18 13:53:25 6420 [Note] InnoDB: Waiting for purge to start

2018-11-18 13:53:25 6420 [Note] InnoDB: 5.6.42 started; log sequence number 0

A random root password has been set. You will find it in '/root/.mysql_secret'.

2018-11-18 13:53:26 6420 [Note] Binlog end

2018-11-18 13:53:26 6420 [Note] InnoDB: FTS optimize thread exiting.

2018-11-18 13:53:26 6420 [Note] InnoDB: Starting shutdown...

2018-11-18 13:53:27 6420 [Note] InnoDB: Shutdown completed; log sequence number 1625977

 

 

2018-11-18 13:53:27 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-11-18 13:53:27 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

2018-11-18 13:53:27 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 6444 ...

2018-11-18 13:53:27 6444 [Note] InnoDB: Using atomics to ref count buffer pool pages

2018-11-18 13:53:27 6444 [Note] InnoDB: The InnoDB memory heap is disabled

2018-11-18 13:53:27 6444 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2018-11-18 13:53:27 6444 [Note] InnoDB: Memory barrier is not used

2018-11-18 13:53:27 6444 [Note] InnoDB: Compressed tables use zlib 1.2.11

2018-11-18 13:53:27 6444 [Note] InnoDB: Using Linux native AIO

2018-11-18 13:53:27 6444 [Note] InnoDB: Using CPU crc32 instructions

2018-11-18 13:53:27 6444 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2018-11-18 13:53:27 6444 [Note] InnoDB: Completed initialization of buffer pool

2018-11-18 13:53:27 6444 [Note] InnoDB: Highest supported file format is Barracuda.

2018-11-18 13:53:27 6444 [Note] InnoDB: 128 rollback segment(s) are active.

2018-11-18 13:53:27 6444 [Note] InnoDB: Waiting for purge to start

2018-11-18 13:53:27 6444 [Note] InnoDB: 5.6.42 started; log sequence number 1625977

2018-11-18 13:53:27 6444 [Note] Binlog end

2018-11-18 13:53:27 6444 [Note] InnoDB: FTS optimize thread exiting.

2018-11-18 13:53:27 6444 [Note] InnoDB: Starting shutdown...

2018-11-18 13:53:29 6444 [Note] InnoDB: Shutdown completed; log sequence number 1625987

 

 

 

 

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !

You will find that password in '/root/.mysql_secret'.

 

You must change that password on your first connect,

no other statement but 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

 

Also, the account for the anonymous user has been removed.

 

In addition, you can run:

 

  /usr/bin/mysql_secure_installation

 

which will also give you the option of removing the test database.

This is strongly recommended for production servers.

 

See the manual for more instructions.

 

Please report any problems at http://bugs.mysql.com/

 

The latest information about MySQL is available on the web at

 

  http://www.mysql.com

 

Support MySQL by buying support/licenses at http://shop.mysql.com

 

WARNING: Found existing config file /usr/my.cnf on the system.

Because this file might be in use, it was not replaced,

but was used in bootstrap (unless you used --defaults-file)

and when you later start the server.

The new default config file was created as /usr/my-new.cnf,

please compare it with your file and take the changes you need.

其中有兩句指明mysql安裝時給root設定了一個隨機的初始密碼:

密碼的位置放在'/root/.mysql_secret'檔案中

用於第一次登陸mysql時使用的,登陸之後會強制修改一下

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !

You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,

no other statement but 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

 

檢視該檔案,可以看到我在重灌mysql時新生成一個隨機密碼

 

 

ps –ef|grep –i mysql 看是否有mysql程序

 

 

用rpm –qa |grep –I mysql看下mysql是否安裝成功了,看到兩個mysql的元件,就是安裝成功了

 

 

5.6以後要設定一個root賬號的隨機密碼

密碼儲存到root/.mysql_secret檔案裡

 

 

後邊需要用這個初始的密碼登入mysql

啟動服務:service mysql start

 

ps –ef |grep mysql 看有沒有mysql服務

 

登入資料庫:

mysql –uroot –p 敲回車

然後輸入隨機密碼

登入後,提示一些資訊

 

 

如連線執行緒id、版本什麼的

show databases; 檢視資料庫有哪些庫

在使用前要設定一個自己的密碼

會要求重置隨機密碼

 

 

重置密碼方法:set password=password(‘root’);

是給當前使用者設定密碼為root

 

再執行 show databases;

mysql會自帶一些系統庫:

information_schema存一些統計資料

performance_schema存一些狀態資料,

mysql存的資料用於監控、許可權、賬號等

test是測試庫,用於做測試用的

 

如果重新安裝,資料目錄沒變的話,那麼之前的庫還是存在的