yum\rpm安装
yum install mysql-server
/etc/init.d/mysql start
二进制包安装 5.6.39
提前下载好安装包:mysql-5.6.39-linux-glibc2.12-x86_64
tar xvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
cp mysql-5.6.39-linux-glibc2.12-x86_64 /application/mysql -r
groupadd mysql
useradd mysql -g mysql
cd /application/mysql/
chown -R mysql:mysql data
yum install libaio* -y
yum -y install perl perl-devel
yum install -y perl-Data-Dumper
./scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
cp support-files/mysql.server /etc/init.d/mysqld
rpm -qa |grep maria*
yum remove mariadb-libs
cp /application/mysql/my.cnf /etc/
----------------------------------------------------------------------------
[root@localhost ~]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /application/mysql
datadir = /application/mysql/data
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
datadir = /usr/local/mysql/data
# port = .....
# server_id = .....
#socket = /tmp/mysql.sock
socket = /var/lib/mysql/mysql.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
[client]
#socket = /tmp/mysql.sock
socket = /var/lib/mysql/mysql.sock
[mysql.server]
#socket = /var/lib/mysql/mysql.sock
#socket = /tmp/mysql.sock
user=mysql
basedir=/usr/local/mysql
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
-----------------------------------------------------------------------------
/etc/init.d/mysqld restart
[root@localhost ~]# echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile
[root@localhost ~]# tail -5 /etc/profile
done
unset i
unset -f pathmunge
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]# source /etc/profile
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@zabbix bin]# /etc/init.d/mysqld restart
[root@zabbix bin]# mysqladmin -uroot password 123456 //修改root密码
数据库查看命令:
mysql> select version();
mysql> select user,host from mysql.user;
mysql> show variables like 'socket';
mysql> show grants for zabbix@'localhost';
mysql> drop user zabbix@'%';
mysql> drop user zabbix@'loacalhost';
mysql> create user zabbix@'localhost' identified by 'zabbix';
mysql> grant all privileges on zabbox.* to zabbix@'localhost';
mysql> GRANT ALL ON *.* TO user@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> flush privileges;
数据库开机启动:
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
源码编译安装 5.6.17(先卸载自带的mariadb)
1.下载源码安装包:mysql-5.6.17.tar.gz
2.解压:tar zxvf mysql-5.6.17.tar.gz
3.安装gcc
yum install make gcc-c++ cmake bison-devel ncurses-devel libaio -y
yum install libaio libaio-devel -y
yum install perl-Data-Dumper -y
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
mv mysql-5.6.17 /usr/local/mysql
cd /usr/local/mysql
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DSYSCONFDIR=/usr/local/mysql \ -DMYSQL_DATADIR=/home/data/mysql/3306/data \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DMYSQL_USER=mysql
编译安装
make
make install
更改目录所有者为mysql并创建相关目录
chown -R mysql:mysql /usr/local/mysql
mkdir -p /home/data/mysql/3306/data/
mkdir -p /home /data/mysql/3306/binlog/
mkdir -p /home /data/mysql/3306/relaylog/
chown -R mysql:mysql /home /data/mysql/
对数据库进行初始化chmod +x /usr/local/mysql/scripts/mysql_install_db
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql \
--datadir=/home/data/mysql/3306/data --user=mysql#拷贝配置文件 cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf #修改my.cnf配置 vim /etc/my.cnf [mysqld] 添加: datadir=/usr/local/mysql/data default-storage-engine=InnoDB
cd support-files/
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
echo export PATH=$PATH:/usr/local/mysql/bin >> /etc/profile && source /etc/profile
mysql[root@db-node01 ~]# netstat -lntup Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 710/sshd tcp6 0 0 :::3306 :::* LISTEN 16025/mysqld tcp6 0 0 :::22 :::* LISTEN 710/sshd [root@db-node01 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.17 Source distribution Copyright (c) 2000, 2014, 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> \q Bye [root@db-node01 ~]#
修改root密码(默认为空)
mysqladmin -uroot password 123456
源码软件结合yum/rpm安装
把源码软件制作成符合要求的rpm包,放在yum仓库,然后通过yum安装。