CentOS7.9 MySQL5.1 安装()

1.下载相关mysql源码包

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.1.63-linux-x86_64-glibc23.tar.gz

2.安装相关依赖包

yum install bison gcc gcc-c++ make autoconf automake ncurses-devel

3.创建相关用户组和用户

groupadd mysql
useradd -g mysql mysql

4.创建相关目录并修改目录权限

mkdir -p /usr/local/mysql
mkdir -p /data/3306mysql/data
chown mysql:mysql /usr/local/mysql -R
chown mysql:mysql /data/3306mysql/data -R

5.编译安装mysql

tar zxf mysql-5.1.63.tar.gz
cd mysql-5.1.63
./configure --prefix=/usr/local/mysql  \
--with-charset=utf8  \
--with-collation=utf8_general_ci  \
--with-extra-charsets=all  \
--with-big-tables  \
--with-unix-socket-path=/data/3306mysql/mysql.sock  \
--with-plugins=all 
make && make install

参数说明:

prefix                                           mysql安装路径
with-charset                                默认字符编码
with-collation                               默认字符编码集
with-extra-charsets                     校验字符
with-big-tables                            支持行数操作4G的表
with-unix-socket-path socket      套接字路径
with-plugins                               用户支持Innodb等其他存储引擎

6.安装默认数据库(初始化授权表)
用mysql用户执行:

/usr/local/mysql/scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql  --datadir=/data/3306mysql/data

7.复制并修改配置文件

cp  /usr/local/mysql/support-files/my-huge.cnf  my.cnf

由于配置文件因实例的不同而有所不同,因此分单实例和多实例来修改配置文件
=>单实例

[mysqld]
port  = 3306
socket  = /data/3306mysql/mysql.sock
basedir  = /usr/local/mysql
datadir  = /data/3306mysql/data
skip-external-locking
key_buffer_size = 512M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_type = 0
#query_cache_size = 32M
thread_concurrency = 8
skip-name-resolve
skip-slave-start
default_storage_engine=InnoDB
connect_timeout=30
max_user_connections = 200
max_connections = 500
max_connect_errors = 1000000
binlog_format = mixed
max_binlog_size = 512M
binlog_cache_size = 4194304
tmp_table_size = 256M
max_heap_table_size = 1024M
tmpdir = /data/3306mysql/tmp
slave_load_tmpdir=/data/3306mysql/tmp
slow-query-log-file = /data/3306mysql/data/slowquery.log
long_query_time = 2
log-queries-not-using-indexes = true
log-slave-updates
init-connect = 'set names utf8'
log-bin=mysql-bin
server-id = 1111
innodb_data_home_dir = /data/3306mysql/data
innodb_log_group_home_dir = /data/3306mysql/data
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 256M
innodb_log_buffer_size = 128M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_file_per_table = 1
innodb_support_xa = false
innodb_io_capacity = 500

=>多实例
多实例参数的配置与单实例不同之处在于:
配置文件中添加一选项[mysqld_multi]
将[mysqld]修改为mysqld数字

[mysqld_multi]
mysqld  = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log  = /home/mysql/multi.log
user  = root

8.启动数据库
数据库的启动也因实例的不同启动方式也有所不同,因此也分单实例的启动和多实例的启动
=>单实例启动
单实例的启动方式有三种:第一种是利用mysql.server方式启动;第二种是利用mysqld_safe方式启动;第三种是利用mysqld方式启动
方式一:

vim /usr/local/mysql/support-files/mysql.server
basedir = /usr/local/mysql
datadir = /data/3306mysql/data
/usr/local/mysql/support-files/mysql.server start

方式二:

/usr/local/mysql/bin/mysqld_safe  --defaults-file=/etc/my.cnf &

方式三:

/usr/local/mysql/bin/mysqld  --defaults-file=/etc/my.cnf &

=>多实例启动
多实例的启动可以通过mysqld_multi方式来启动。
启动某一个实例:(例如启动3306端口的实例)

mysqld_multi start 3306

启动所有实例:

mysqld_multi start

9.运行安全程序
安全程序的作用是修改相关权限(即修改mysql库中相关数据),具体为:设置root用户密码、删除匿名用户、禁止root用户远程登录、删除测试数据库等。该程序只能在单实例启动,因此在多实例中可以在安装第一个实例时运行该安全程序,其他实例复制该mysql文件以覆盖本目录mysql文件。
运行安全程序脚本:

/usr/local/mysql/bin/mysql_secure_installation

根据提示进行相关操作
10.测试
登录mysql服务器,看数据库是否正确加载,权限时候正确

mysql -uroot -P3306 -h127.0.0.1 -p
————————

1.下载相关mysql源码包

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.1.63-linux-x86_64-glibc23.tar.gz

2.安装相关依赖包

yum install bison gcc gcc-c++ make autoconf automake ncurses-devel

3.创建相关用户组和用户

groupadd mysql
useradd -g mysql mysql

4.创建相关目录并修改目录权限

mkdir -p /usr/local/mysql
mkdir -p /data/3306mysql/data
chown mysql:mysql /usr/local/mysql -R
chown mysql:mysql /data/3306mysql/data -R

5.编译安装mysql

tar zxf mysql-5.1.63.tar.gz
cd mysql-5.1.63
./configure --prefix=/usr/local/mysql  \
--with-charset=utf8  \
--with-collation=utf8_general_ci  \
--with-extra-charsets=all  \
--with-big-tables  \
--with-unix-socket-path=/data/3306mysql/mysql.sock  \
--with-plugins=all 
make && make install

参数说明:

prefix                                           mysql安装路径
with-charset                                默认字符编码
with-collation                               默认字符编码集
with-extra-charsets                     校验字符
with-big-tables                            支持行数操作4G的表
with-unix-socket-path socket      套接字路径
with-plugins                               用户支持Innodb等其他存储引擎

6.安装默认数据库(初始化授权表)
用mysql用户执行:

/usr/local/mysql/scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql  --datadir=/data/3306mysql/data

7.复制并修改配置文件

cp  /usr/local/mysql/support-files/my-huge.cnf  my.cnf

由于配置文件因实例的不同而有所不同,因此分单实例和多实例来修改配置文件
=>单实例

[mysqld]
port  = 3306
socket  = /data/3306mysql/mysql.sock
basedir  = /usr/local/mysql
datadir  = /data/3306mysql/data
skip-external-locking
key_buffer_size = 512M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_type = 0
#query_cache_size = 32M
thread_concurrency = 8
skip-name-resolve
skip-slave-start
default_storage_engine=InnoDB
connect_timeout=30
max_user_connections = 200
max_connections = 500
max_connect_errors = 1000000
binlog_format = mixed
max_binlog_size = 512M
binlog_cache_size = 4194304
tmp_table_size = 256M
max_heap_table_size = 1024M
tmpdir = /data/3306mysql/tmp
slave_load_tmpdir=/data/3306mysql/tmp
slow-query-log-file = /data/3306mysql/data/slowquery.log
long_query_time = 2
log-queries-not-using-indexes = true
log-slave-updates
init-connect = 'set names utf8'
log-bin=mysql-bin
server-id = 1111
innodb_data_home_dir = /data/3306mysql/data
innodb_log_group_home_dir = /data/3306mysql/data
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 256M
innodb_log_buffer_size = 128M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_file_per_table = 1
innodb_support_xa = false
innodb_io_capacity = 500

=>多实例
多实例参数的配置与单实例不同之处在于:
配置文件中添加一选项[mysqld_multi]
将[mysqld]修改为mysqld数字

[mysqld_multi]
mysqld  = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log  = /home/mysql/multi.log
user  = root

8.启动数据库
数据库的启动也因实例的不同启动方式也有所不同,因此也分单实例的启动和多实例的启动
=>单实例启动
单实例的启动方式有三种:第一种是利用mysql.server方式启动;第二种是利用mysqld_safe方式启动;第三种是利用mysqld方式启动
方式一:

vim /usr/local/mysql/support-files/mysql.server
basedir = /usr/local/mysql
datadir = /data/3306mysql/data
/usr/local/mysql/support-files/mysql.server start

方式二:

/usr/local/mysql/bin/mysqld_safe  --defaults-file=/etc/my.cnf &

方式三:

/usr/local/mysql/bin/mysqld  --defaults-file=/etc/my.cnf &

=>多实例启动
多实例的启动可以通过mysqld_multi方式来启动。
启动某一个实例:(例如启动3306端口的实例)

mysqld_multi start 3306

启动所有实例:

mysqld_multi start

9.运行安全程序
安全程序的作用是修改相关权限(即修改mysql库中相关数据),具体为:设置root用户密码、删除匿名用户、禁止root用户远程登录、删除测试数据库等。该程序只能在单实例启动,因此在多实例中可以在安装第一个实例时运行该安全程序,其他实例复制该mysql文件以覆盖本目录mysql文件。
运行安全程序脚本:

/usr/local/mysql/bin/mysql_secure_installation

根据提示进行相关操作
10.测试
登录mysql服务器,看数据库是否正确加载,权限时候正确

mysql -uroot -P3306 -h127.0.0.1 -p