脚踏实地、勇往直前!
全部博文(1005)
分类: Mysql/postgreSQL
2016-12-12 11:18:43
版本:社区版 5.6.34
我这里下载的是mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
1.创建mysql用户和用户组
#groupadd mysql
#useradd -g mysql mysql
#passwd mysql
2.下载解压二进制文件,解压,进入解压出来的文件
[root@host01 db]# tar -xvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
[root@host01 db]# mv mysql-5.6.34-linux-glibc2.5-x86_64 mysqlmha
3.在mysqlmha目录下创建如下文件夹
[mysql@host01 mysqlmha]$ cd /db/mysqlmha
[mysql@host01 mysqlmha]$ mkdir conf ## 配置文件目录
[mysql@host01 mysqlmha]$ mkdir data ##数据文件
[mysql@host01 mysqlmha]$ mkdir redolog ##redo日志文件
[mysql@host01 mysqlmha]$ mkdir ibdata ##ibdata文件
[mysql@host01 mysqlmha]$ mkdir -p mysqllog/relaylog ##主从环境relaylog
[mysql@host01 mysqlmha]$ mkdir -p mysqllog/logfile ##错误日志文件
[mysql@host01 mysqlmha]$ mkdir -p mysqllog/binlog ##binlog文件
[mysql@host01 mysqlmha]$ mkdir -p external_data ##secure_file_priv参数指定路径
4.创建配置文件
在conf目录下创建配置文件my.cnf,配置文件内容附后.
5.更改文件夹mysqlmha的文件所属用户
[root@host01 db]# chown -R mysql:mysql mysqlmha
6.安装数据库
[root@host01 db]#cd /db/mysqlmha/scripts
[root@host01 db]#./mysql_install_db --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data
执行该步骤的时候有可能遇到如下错误:
错误1:
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper
解决方法:安装autoconf库
命令:yum -y install autoconf
错误2:
-bash: ./mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
貌似提示注释器错误,没有/usr/bin/perl文件或者档案,解决办法(安装perl跟perl-devel即可):
执行:yum -y install perl perl-devel
错误3:
[root@localhost scripts]# ./mysql_install_db --user=mysql --basedir=/opt/mysql5640 --datadir=/opt/mysql5640/data
Installing MySQL system tables.../opt/mysql5640/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法
[root@example.com data]# yum install -y libaio
错误4:
Installing MySQL system tables.../opt/mysql5640/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
解决办法:
yum -y install numactl
7.创建软连接
[root@host01 db]# mkdir -p /usr/local/mysql/bin
[root@host01 db]# ln -s /db/mysqlmha/bin/mysqld /usr/local/mysql/bin/mysqld
[root@host01 db]# chown -R mysql:mysql /usr/local/mysql
8.启动数据库
[root@host01 db]#./mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql
9.登陆数据库修改密码
数据库安装后root账号的初始化密码为空,不需要密码即可登陆数据库,为了安全起见,登陆后立即修改数据库密码
[root@host01 db]$./mysql -h localhost -u root -S /db/mysqlmha/data/mysql.sock
update mysql.user set password=PASSWORD('mysql') where user='root' and host='localhost';
flush privileges;
删除用户名或是密码为空的账号
delete from mysql.user where user='';
delete from mysql.user where password='';
10.关闭数据库后重启
[mysql@host01 bin]$ ./mysqladmin -h localhost -u root -p -S /db/mysqlmha/data/mysql.sock shutdown
[mysql@host01 bin]$./mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql
11.把mysql加入系统自启动
[root@host01 ~]# more /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
/db/mysqlmha/bin/mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql &
12. 5.6.34版本有bug,某些表需要重建,点击链接安装部署实施.
http://blog.chinaunix.net/uid-77311-id-5756660.html
centos 7自动启另外一种方式:
1.touch /usr/lib/systemd/system/mysql.service 2.该文件内容如下: [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/opt/mysql5640/bin/mysqld_safe --defaults-file=/opt/mysql5640/conf/my.cnf --user=mysql LimitNOFILE = 5000 #Restart=on-failure #RestartPreventExitStatus=1 #PrivateTmp=false 3.通过systemctl启动 systemctl start mysql 遇到无法启动的情况下需要做如下操作 [root@localhost bin]# systemctl start mysql Warning: mysql.service changed on disk. Run 'systemctl daemon-reload' to reload units. 解决办法: [root@localhost bin]# systemctl daemon-reload 4.启用开启自启动 systemctl enable mysql 5.查看启动状态 systemctl status mysql |