CentOS二进制安装MySQL

本文详细介绍在Linux环境下安装和配置MySQL数据库的过程,包括检查现有安装、上传并解压二进制包、创建用户、编辑配置文件、调整权限、安装服务、配置环境变量及启动服务等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.检查是否有安装mysql

[root@hadoop001 ~]# rpm -qa|grep mysql
[root@hadoop001 ~]# ps aux|grep mysql
root      10723  0.0  0.0 103240   876 pts/2    S+   06:03   0:00 grep mysql

2.上传mysql二进制包,解压

从本地电脑或者网站下载二进制安装包,上传至/usr/local,并作软连接。
[root@hadoop001 local]# tar -zxvf mysql-5.6.23-linux-glibc2.5-x86_64
[root@hadoop001 local]# ln -s mysql-5.6.23-linux-glibc2.5-x86_64 mysql

3.创建mysql相关用户

[root@hadoop001 local]# groupadd -g 101 dba
[root@hadoop001 local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
[root@hadoop001 local]# id mysqladmin
uid=514(mysqladmin) gid=101(dba) 组=101(dba),0(root)

4.编辑/etc/my.cnf

[client]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock
 
[mysqld]
port            = 3306
socket          = /usr/local/mysql/data/mysql.sock

skip-external-locking
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size= 32M
max_allowed_packet = 16M
myisam_sort_buffer_size=128M
tmp_table_size=32M

table_open_cache = 512
thread_cache_size = 8
wait_timeout = 86400
interactive_timeout = 86400
max_connections = 600

# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 32

#isolation level and default engine 
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED

server-id  = 1
basedir     = /usr/local/mysql
datadir     = /usr/local/mysql/data
pid-file     = /usr/local/mysql/data/hostname.pid

#open performance schema
log-warnings
sysdate-is-now

binlog_format = MIXED
log_bin_trust_function_creators=1
log-error  = /usr/local/mysql/data/hostname.err
log-bin=/usr/local/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file  = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err

#for replication slave
#log-slave-updates 
#sync_binlog = 1

#for innodb options 
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ibdata1:500M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/arch
innodb_log_files_in_group = 2
innodb_log_file_size = 200M
#修改这个参数
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 50M
innodb_log_buffer_size = 16M

innodb_lock_wait_timeout = 100
#innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_locks_unsafe_for_binlog=1

#innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads=4
innodb-write-io-threads=4
innodb-io-capacity=200
#purge threads change default(0) to 1 for purge
innodb_purge_threads=1
innodb_use_native_aio=on

#case-sensitive file names and separate tablespace
innodb_file_per_table = 1
lower_case_table_names=1

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[mysqlhotcopy]
interactive-timeout

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

5.修改mysql相关文件跟目录权限

[root@hadoop001 local]# chmod 640 /etc/my.cfg
[root@hadoop001 local]# cp /etc/skel/.* /usr/local/mysql/
[root@hadoop001 local]# chown -R mysqladmin.dba mysql
[root@hadoop001 local]# chown -R mysqladmin.dba mysql/*
[root@hadoop001 local]# chown -R mysqladmin.dba mysql-5.6.23-linux-glibc2.5-x86_64
[root@hadoop001 local]# chmod -R 755 mysql
[root@hadoop001 local]# chmod -R 755 mysql/*
[root@hadoop001 local]# chmod -R 755 mysql-5.6.23-linux-glibc2.5-x86_64

6.安装mysql

切换到mysqladmin用户
[root@hadoop001 ~]# su - mysqladmin
[mysqladmin@hadoop001 ~]$ pwd
/usr/local/mysql
#创建binlog日志存储的文件夹
[mysqladmin@hadoop001 ~]$ mkdir arch
[mysqladmin@hadoop001 ~]$scripts/mysql_install_db  --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#复制相应的文件到系统目录
[root@hadoop001 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql 
[root@hadoop001 mysql]# chmod +x /etc/rc.d/init.d/mysql
[root@hadoop001 mysql]# chkconfig --del mysql
[root@hadoop001 mysql]# chkconfig --add mysql
[root@hadoop001 mysql]# chkconfig --level 345 mysql on
在开机文件中写入开机启动mysql
[mysqladmin@hadoop001 ~]$ cat /etc/rc.local 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
su - mysqladmin -c "/etc/inid./mysql start"

7.配置环境变量

添加环境变量到/etc/profile中
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@hadoop001 ~]# source /etc/profile

8.启动mysql服务

[mysqladmin@hadoop001 ~]$ service mysql start
[mysqladmin@hadoop001 ~]$ ps aux|grep mysql
root      10770  0.0  0.1 145340  1616 pts/1    S    06:17   0:00 su - mysqladmin
514       11705  0.0  0.1 106184  1536 pts/1    S    06:27   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/hostname.pid
514       12386  0.3 26.7 2103188 269140 pts/1  Sl   06:27   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/hostname.err --pid-file=/usr/local/mysql/data/hostname.pid --socket=/usr/local/mysql/data/mysql.sock --port=3306
514       12414  0.0  0.0 103240   876 pts/1    S+   06:28   0:00 grep mysql
出现如下界面表示进入数据库成功
[mysqladmin@hadoop001 ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值