MySQL的安装有三种方式
1.RPM安装MySQL
2.yum源的安装方式
在本篇文章中,不对上述的两种安装方式进行过多的阐述,对第三种安装方式进行详细的介绍
3.源代码编译安装
参考文档:https://github.com/Hackeruncle/MySQL/blob/master/MySQL%205.6.23%20Install.txt
1.下载(root用户下进行操作)
将mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz安装到/usr/local目录下
$>cd /usr/local
$>wget https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
2.检查是否安装过mysql(root用户下进行操作)
查看是否有mysql进程
$>ps -ef | grep mysqld
查看是否有mysql的rpm包
$>rpm -qa | grep -i mysql
3.解压并移动(root用户下进行操作)
$>tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
$>mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql
4.创建一个用户组和用户(root用户下进行操作)
创建一个组(-g指定组ID)
$>groupadd -g 101 dba
创建一个用户(-u指定用户ID -G表示属于哪个组 -d表示创建的家目录在哪里)
$>useradd -u 514 -g dba -G root -d /opt/app/mysql mysqladmin
查看mysqladmin用户
$>id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
为mysqladmin用户设置密码(密码为mysql 注意这里的mysqladmin密码为Linux系统用户的密码非mysql数据库的登陆用户的密码)
$>passwd mysqladmin
5.编辑文件/etc/my.cnf(root用户下进行操作)
MySQL默认启动过程: /etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf-> –defaults-extra-file->~/my.cnf
$>vi /etc/my.cnf
将下面内容复制进去(修改一个地方)
[client]
port = 3306
socket = /opt/app/mysql/data/mysql.sock
[mysqld]
port = 3306
socket = /opt/app/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 = /opt/app/mysql
datadir = /opt/app/mysql/data
pid-file = /opt/app/mysql/data/hostname.pid
#open performance schema
log-warnings
sysdate-is-now
binlog_format = MIXED
log_bin_trust_function_creators=1
log-error = /opt/app/mysql/data/hostname.err
log-bin = /opt/app/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file = /opt/app/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file = /opt/app/mysql/data/slow_log.err
#for replication slave
#log-slave-updates
#sync_binlog = 1
#for innodb options
innodb_data_home_dir = /opt/app/mysql/data/
innodb_data_file_path = ibdata1:500M:autoextend
innodb_log_group_home_dir = /opt/app/mysql/arch
innodb_log_files_in_group = 2
innodb_log_file_size = 200M
#这里需要改变
#根据自己的电脑内存来配置innodb_buffer_pool_size的值
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
6.改变/etc/my.cnf和/opt/app/mysql的所属组和用户以及权限(在root用户下进行操作)
改变/etc/my.cnf的所属组和用户
$>chown mysqladmin:dba /etc/my.cnf
授予640权限
$>chmod 640 /etc/my.cnf
$>ll my.cnf
-rw-r----- 1 mysqladmin dba 2201 Aug 25 23:09 my.cnf
改变/opt/app/mysql/mysql的所属组和用户
$>chown -R mysqladmin:dba /opt/app/mysql
授予755权限
$>chmod -R 755 /opt/app/mysql
7.执行命令,进行mysql的安装(mysqladmin用户下进行操作)
注意:必须切换成mysqladmin用户来启动MySQL,如果使用root用户会报错
$>su - mysqladmin
$>pwd
/opt/app/mysql
创建目录arch(重要)
$>cd /opt/app/mysql
$>>mkdir arch
按照脚本进行安装(重要)
$>scripts/mysql_install_db --user=mysqladmin --basedir=/opt/app/mysql --datadir=/opt/app/mysql/data
报错:
Installing MySQL system tables…./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory #缺少libaio.so 包
开始排错:
1.查看版本
$>cat /proc/version
Linux version 2.6.18-164.11.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Wed Jan 20 07:32:21 EST 2010
2.$>rpm -qa |grep gcc
libgcc-4.1.2-46.el5_4.2
libgcc-4.1.2-46.el5_4.2
3.使用root用户进行安装
$>yum -y install libaio
8.再次进行安装(mysqladmin用户下进行操作)
安装的过程中,指定user、basedir、datadir
$>scripts/mysql_install_db --user=mysqladmin --basedir=/opt/app/mysql --datadir=/opt/app/mysql/data
9.确认mysql服务(root用户下进行操作)
切换目录到/opt/app/mysql
$>cd /opt/app/mysql
将服务文件拷贝到init.d下,并重命名为mysql
$>cp support-files/mysql.server /etc/rc.d/init.d/mysql
赋予可执行权限
$>chmod +x /etc/rc.d/init.d/mysql
删除服务
$>chkconfig --del mysql
添加服务
$>chkconfig --add mysql
$>chkconfig --level 345 mysql on
9.启动mysql服务,查看进程(mysqladmin用户下进行操作)
切换到mysqladmin用户
$>su - mysqladmin
$>pwd
/usr/local/mysql
删除my.cnf文件
$>rm -rf my.cnf
启动
$>bin/mysqld_safe &
查看mysql的相关进程
$>ps -ef | grep mysqld
查看mysql端口及状态
$>netstat -tulnp | grep mysql
查看mysql进程的状态
$>service mysql status
见下图:
10.登陆到mysql
$>mysql
登陆成功:
11.编译过程中的其它问题
切换用户显示-bash-4.1$的解决办法
将mysqladmin的环境变量拷贝至/opt/app/mysql目录下
$>cp -r /etc/skel/.* /opt/app/mysql