1. 程式人生 > >MySQL 安裝方法

MySQL 安裝方法

mysql 安裝方法

本博文主要是為了增加記憶同時促進大家共同學習,如在發現中有理解錯誤請幫忙留言改正,不勝感激。

本次主要是mysql-5.5.54 的安裝

基礎環境為:

centos 6.8

一、下載mysql-5.5.54 安裝包

創建軟件存放目錄

mkdir /home/softwares/

cd /home/softwares/

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.54.tar.gz

二、安裝mysql 依賴包

yum install -y cmake;

yum install -y gcc gcc-c++ ;

yum install -y ncurses-devel.x86_64 ;

yum install -y cmake.x86_64 ;

yum install -y libaio.x86_64 ;

yum install -y bison.x86_64 ;

yum install -y gcc-c++.x86_64;

yum install -y perl-Module-Build;

yum install -y libtool zilib-devel ;

yum install -y libaio.x86_64;

yum install -y perl.x86_64;

yum install -y perl-Module-Pluggable.x86_64;

yum install -y perl-Pod-Escapes.x86_64;

yum install -y perl-Pod-Simple.x86_64;

yum install -y perl-libs.x86_64;

yum install -y perl-version.x86_64 ;

yum install –y openssl openssl-devel ncurses ncurses-devel;

2、創建用戶和組分區

groupadd mysql

useradd mysql -g mysql -M -s /sbin/nologin

3、解壓mysql-5.5.54.tar.gz

tar -zxvf mysql-5.5.54.tar.gz && cd mysql-5.5.54/ && chmod +x *

4、編譯安裝

cmake \ ##相當於config
-DCMAKE_INSTALL_PREFIX=/u01/app/mysql/db \ ##數據庫安裝的目錄
-DSYSCONFDIR=/u01/app/mysql/db/etc \ ##數據庫安裝的配置文件,不用原來的默認文件可以避免多次升級的時候讀取錯誤的配置文件
-DMYSQL_DATADIR=/u01/data/mysql/db/data \ ##數據庫默認存放庫表存放的位置
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/u01/app/mysql/db/mysql.sock \ ##本地通信日誌
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \

make install

5、編寫配置文件

cd /u01/app/mysql/db/ && mkdir etc && cd etc

mkdir etc

vi my.cnf

cat my.cnf

[mysqld]

#########data###########

user=mysql

basedir = /u01/app/mysql/db

datadir = /u01/app/mysql/data

innodb_log_group_home_dir=/u01/app/mysql/engine/innolog

innodb_log_file_size = 50M

innodb_data_home_dir=/u01/app/mysql/engine/innodata

#innodb_data_file_path = ibdata1:100M;ibdata2:150M:autoextend

innodb_data_file_path = ibdata1:100M:autoextend

log-bin = /u01/app/mysql/log/mysql-binlog

log-bin-index = /u01/app/mysql/log/mysql-bin.index

binlog_cache_size = 32M

max_binlog_size=512M

binlog_format=row

innodb_file_per_table=1

log-error = /u01/app/mysql/mysql-error.log

pid-file = /u01/app/mysql/mysql.pid

skip-name-resolve

socket=/u01/app/mysql/mysql.sock

############pool#########

#*******skip-innodb*********

innodb_additional_mem_pool_size = 64M

innodb_buffer_pool_size=256M

innodb_write_io_threads = 8

innodb_read_io_threads = 8

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 16M

innodb_log_file_size = 512M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

port=3306

server-id= 1

# *** global cache ***

read_buffer_size = 32M

read_rnd_buffer_size = 128M

sort_buffer_size = 64M

join_buffer_size = 64M

# *** query cache ***

query_cache_size = 128M

query_cache_limit = 4M

# *** bin log ***

#log_slave_updates

log_warnings

###########others#########

#***transaction***

default-storage-engine = INNODB

transaction_isolation = REPEATABLE-READ

# *** thread ***

thread_cache_size = 16

thread_stack = 512K

#*** network ***

back_log = 512

#skip-networking

max_connections = 3000

max_connect_errors = 30

table_open_cache = 4096

max_allowed_packet = 32M

max_heap_table_size = 512M

#*** char set ***

character-set-server = utf8

#explicit_defaults_for_timestamp = true

# *** tmp table ***

tmp_table_size = 128M

# *** slow query log ***

slow_query_log

long_query_time = 10

[mysqldump]

quick

max_allowed_packet = 32M

[mysql]

auto-rehash

[myisamchk]

key_buffer_size = 12M

sort_buffer_size = 12M

read_buffer = 32M

write_buffer = 32M

[mysqlhotcopy]

interactive-timeout

[client]

socket=/u01/app/mysql/mysql.sock

port=3306

6、將mysql啟動腳本腳本命令復制到/etc/init.d/

cp /u01/app/mysql/db/support-files/mysql.server /etc/init.d/mysqld && chmod +x /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

7、根據my.cnf 創建目錄他不會自動創建目錄

mkdir -p /u01/app/mysql/data/engine/innolog

mkdir -p /u01/app/mysql/data/engine/innodata

mkdir -p /u01/app/mysql/data/mysql-binlog

mkdir -p /u01/app/mysql/log/

chown mysql. /u01/app/mysql/ -R

cd /u01/app/mysql/db

8、初始化語句數據庫安裝指定的目錄,數據庫默認存放目錄

./scripts/mysql_install_db --basedir=/u01/app/mysql/db --datadir=/u01/app/mysql/data --user=mysql

更改環境變量

vim ~/.bash_profile

PATH=$PATH:$HOME/bin:/u01/app/mysql/db/bin/

環境變量生效

source ~/.bash_profile

如果報錯:

/etc/init.d/mysqld start

配置文件的問題

Starting MySQL... ERROR! The server quit without updating PID file (/data/mysql/mysql.pid).

一般需要自己查詢配置文件是否設置的參數過大或者過小,查看機器內存是否過小,如果都是可以的請刪除除了db 文件之外的所有 然後重新創建目錄

##########啟動成功之後設置密碼###########

mysqladmin -uroot password "123456"









本文出自 “鎏金兒” 博客,請務必保留此出處http://19930412.blog.51cto.com/6974556/1936560

MySQL 安裝方法