Linux 系統安裝mysql過程記錄

Linux 系統安裝mysql過程記錄

 

  • 資源清單

1 mysql mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
2 linux  CentOS release 6.9 (Final)
3 gcc gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
  • 安裝包

mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz

安裝包中有*glibc*的表示爲源碼編譯後的二進制安裝包,直接安裝不需要再編譯。


登陸官網下載:
 

  • 安裝步驟

  • 創建用戶

以root用戶登錄linux系統,

# useradd mysql
# passwd mysql

安裝
用root用戶上傳mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz 到 /usr/local/
解壓

# tar -zxvf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

修改文件名及所有者

# mv mysql-5.6.37-linux-glibc2.12-x86_64/ mysql-5.6.37
# chown mysql:mysql mysql-5.6.37/

切換mysql用戶,進入mysql-5.6.37目錄
執行安裝命令

$./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.6.37 --datadir=/usr/local/mysql-5.6.37/data

執行安裝命令如果報錯:
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper

需要安裝autoconf庫
可以如下安裝方式
離線安裝
下載autoconf-2.65.tar.gz 
&& tar -xzvf autoconf-2.65.tar.gz
&& cd autoconf-2.65
&& ./configure --prefix=/usr/local
make && make install

在線安裝
yum -y install autoconf

配置文件
安裝完成後進行配置操作
以root用戶進入/usr/local/mysql-5.6.37/support-files/ 路徑
執行

# cp my-default.cnf /etc/my.cnf
# cp mysql.server /etc/init.d/mysql

修改文件/etc/init.d/mysql,修改內容如下:

basedir=/usr/local/mysql-5.6.37
datadir=/usr/local/mysql-5.6.37/data

保存退出

修改/etc/init.d/mysql文件所有者

# chown mysql:mysql mysql


配置環境變量
#vim /etc/profile
在打開的文件中加入如下內容

export MY_SQL_HOME=/usr/local/mysql-5.6.37
export PATH=$PATH:$MY_SQL_HOME/bin

保存退出執行如下命令,使/etc/profile文件生效

#source /etc/profile

啓動mysql

 

file path desc
mysqld $mysql_home/bin The MySQL Server,mysql的服務端
mysqld_safe $mysql_home/bin MySQL Server Startup Script,mysql服務端的啓動腳本
mysql.server $mysql_home/support-files MySQL Server Startup Script,mysql服務端的啓動腳本
mysql_multi $mysql_home/bin Manage Multiple MySQL Servers ,多個mysql服務端的管理器

mysqld:

SQL後臺程序(即MySQL服務器)。要想使用客戶端程序,該程序必須運行,因爲客戶端通過連接服務器來訪問數據庫。

通過mysqld啓動mysql server,啓動時指定啓動參數,如:

$ mysqld  --basedir=/usr/local/mysql-5.6.37 --datadir=/usr/local/mysql-5.6.37/data --character_set_server=utf8

mysqld可跟的參數可以用 $mysqld --help 查看,具體不細講

如果每次啓動都是相同的參數,可以把參數寫入配置文件,配置文件位於/etc/my.cnf,如果沒有,複製$mysql_home/my.cnf 到/etc路徑下

(ps:windows版的配置文件my.ini,linux版的配置文件my.cnf)

該文件默認如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

mysqld從文件my.cnf中的 [mysqld] 和 [server] 下讀取參數

my.cnf文件中默認只有 [mysqld]  ,[server] 可以添加

如:basedir,datadir,字符集的參數沒有,可以添加character_set_server=utf8,添加校對規則collation_server=utf8_bin(server,database存儲數據區分大小寫)

 basedir=/usr/local/mysql-5.6.37
 datadir=/usr/local/mysql-5.6.37/data
 character_set_server=utf8
 collation_server=utf8_bin

配置好/etc/my.cnf文件,可以直接使用mysqld啓動mysql server

$ mysqld

mysqld_safe:

該文件是mysql server的啓動腳本,mysqld_safe腳本從/etc/my.cnf文件的[mysqld]、 [server]和[mysqld_safe]部分讀取參數。

如果my.cnf文件中均爲默認,則會使用linux配置的mysql環境變量中找mysql安裝路徑,並使用該安裝路徑作爲basedir/datadir參數的值啓動mysql server

啓動:

[mysql@localhost ~]$ mysqld_safe
170804 09:38:13 mysqld_safe Logging to '/usr/local/mysql-5.6.37/data/localhost.localdomain.err'.
170804 09:38:13 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.6.37/data

mysql.server:

在Unix中的MySQL分發版中有mysql.server腳本。它可以用於使用System V-style運行目錄來啓動和停止系統服務的系統,例如Linux和Solaris。
mysql.server位於$mysql_home/support-files目錄中。

複製該文件到/etc/init.d/路徑下,文件名改爲mysql,該文件中設置如下參數:

basedir=/usr/local/mysql-5.6.37
datadir=/usr/local/mysql-5.6.37/data

如果你使用Linux 服務器RPM軟件包(MySQL-server-VERSION.rpm), mysql.server腳本將安裝到/etc/init.d目錄下,名爲mysql。你不需要 手動安裝。
啓動:

[mysql@localhost ~]$ service mysql start
Starting MySQL SUCCESS!

停止:

[mysql@localhost ~]$ service mysql stop
Shutting down MySQL.. SUCCESS!
[mysql@localhost ~]$

以這種方式啓動,啓動時會讀取/etc/my.cnf配置文件,從[mysqld]、 [mysql.server]部分讀取參數

修改root用戶密碼

$ service mysql start
登錄mysql及改密碼與配置遠程訪問
修改root用戶密碼
$ mysqladmin -u root password xxxx
xxxx爲自定義的root用戶密碼

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章