linux安裝mysql詳細步驟

最近買了個騰訊雲服務器,搭建環境。html

該筆記用於系統上未裝過mysql的乾淨系統第一次安裝mysql。本身指定安裝目錄,指定數據文件目錄。mysql

linux系統版本: CentOS 7.3 64位linux

安裝源文件版本:mysql-5.7.21-linux-glibc2.12-x86_64.tar.gzsql

mysql安裝位置:/software/mysql數據庫

數據庫文件數據位置:/data/mysqlvim

 

注:未防止混淆,這裏都用絕對路徑執行命令centos

        除了文件內容中的#,這裏全部帶#都是linux命令緩存

  >mysql 是mysql的命令安全

 

步驟:服務器

一、在根目錄下建立文件夾software和數據庫數據文件/data/mysql

#mkdir /software/

#mkdir /data/mysql

 

二、上傳mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz文件到/software下

 

#cd /software/

#tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

 

三、更改解壓縮後的文件夾名稱

#mv /software/mysql-5.7.21-linux-glibc2.12-x86_64/  /software/mysql

 

四、建立mysql用戶組和mysql用戶

#groupadd mysql

#useradd -r -g mysql mysql

 

五、關聯myql用戶到mysql用戶組中

#chown -R mysql:mysql  /software/mysql/

#chown -R mysql:mysql  /data/mysql/

#chown -R mysql  /software/mysql/

#chown -R mysql  /data/mysql

 

六、更改mysql安裝文件夾mysql/的權限

#chmod -R 755 /software/mysql/

 

七、安裝libaio依賴包,因爲我買的騰訊雲服務器centos系統自帶的有這個依賴包因此不須要安裝,不過自帶的依賴包會報錯,後面介紹解決辦法

查詢是否暗轉libaio依賴包

#yum search libaio

若是沒安裝,能夠用下面命令安裝

#yum install libaio

 

八、初始化mysql命令

#cd /software/mysql/bin

#./mysqld --user=mysql --basedir=/software/mysql --datadir=/data/mysql --initialize

在執行上面命令時特別要注意一行內容   

[Note] A temporary password is generated for root@localhost: o*s#gqh)F4Ck

root@localhost: 後面跟的是mysql數據庫登陸的臨時密碼,各人安裝生成的臨時密碼不同

若是初始化時報錯以下:

error while loading shared libraries: libnuma.so.1: cannot open shared objec

是由於libnuma安裝的是32位,咱們這裏須要64位的,執行下面語句就能夠解決

#yum install numactl.x86_64

執行完後從新初始化mysql命令

 

九、啓動mysql服務

# sh /software/mysql/support-files/mysql.server start

上面啓動mysql服務命令是會報錯的,由於沒有修改mysql的配置文件,報錯內容大體以下:

./support-files/mysql.server: line 239: my_print_defaults: command not found
./support-files/mysql.server: line 259: cd: /usr/ local /mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/ local /mysql/bin/mysqld_safe)
 
 
十、修改Mysql配置文件
#vim /software/mysql/support-files/mysql.server
修改前

if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi

修改後

if test -z "$basedir"
then
basedir=/software/mysql
bindir=/software/mysql/bin
if test -z "$datadir"
then
datadir=/data/mysql
fi
sbindir=/software/mysql/bin
libexecdir=/software/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi

保存退出

#cp /software/mysql/support-files/mysql.server  /etc/init.d/mysqld
#chmod 755 /etc/init.d/mysqld

十一、修改my.cnf文件

#vi /etc/my.cnf

將下面內容複製替換當前的my.cnf文件中的內容

[client]
no-beep
socket =/software/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/software/mysql
datadir=/data/mysql
port=3306
pid-file=/software/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /software/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用於每一個數據庫線程的棧大小。默認設置足以知足大多數應用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /data/mysql
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入數據緩存大小,能夠有效提升插入效率,默認爲8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

保存退出

 

十二、啓動mysql

#/etc/init.d/mysqld start

新版本的安裝包會報錯,錯誤內容以下:

Starting MySQL.Logging to '/data/mysql/SZY.err'.
2018-07-02T10:09:03.779928Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
ERROR! The server quit without updating PID file (/software/mysql/mysqld.pid).

由於新版本的mysql安全啓動安裝包只認/usr/local/mysql這個路徑。

解決辦法:

方法一、創建軟鏈接

例 #cd /usr/local/mysql

#ln -s /sofware/mysql/bin/myslqd mysqld

 

方法二、修改mysqld_safe文件(有強迫症的同窗建議這種,我用的這種)

# vim /software/mysql/bin/mysqld_safe

將全部的/usr/local/mysql改成/software/mysql

保存退出。(能夠將這個文件拷出來再修改而後替換)

 

1三、登陸mysql

#/software/mysql/bin/mysql -u root –p

 

1四、輸入臨時密碼。臨時密碼就是第8條root@localhost:後面的內容

 

1五、修改mysql的登陸密碼

>mysql   set password=password('root');

>mysql  grant all privileges on *.* to root@'%' identified by 'root';

>mysql flush privileges;

 

1六、完成,此時mysql的登陸名root  登陸密碼root

相關文章
相關標籤/搜索