最近项目中有用到MySQL,特地研究了一下Mysql的安装及配置。
MySQL的安装分为三种:1、RPM包安装;2、二进制包安装;3、源码安装。
第一种方式比较简单,直接RPM包或者通过yum安装,非常适合初学MySQL的人安装,而第三种源码安装方式比较复杂,适合企业对定制化要求较高时候可以安装。一般项目中使用比较多的是通过二进制包来安装,这种安装方式可以根据企业的不同需求进行相关的自定义配置,比如安装在哪个目录,如何配置等。
现在具体介绍一下Mysql的二进制安装方式
1、下载Mysql5.6版本和解压
这个链接可能会在在未来更新中失效,万一失效可以找一新的下载链接。wget -c http://dev.mysql.com/get/Downloads/MySQL-5.6/ mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz //下载
tar -zxvf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz //解压
mv mysql-5.6.14-linux-glibc2.5-x86_64/ mysql56 //命名为mysql56
2、 安装MySQL5.6版本
linux 中 export 设置环境变量和MySQL安装:export PATH=/usr/local/mysql56/bin:$PATH //每次重启服务器都需要重新设置下
安装数据库:
/usr/local/mysql56/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/mysqldata/node1
安装中遇到小插曲
安装过程中,遇到的错误提示信息1,错误发生原因是缺少perl依赖包:
[root@VM_85_23_centos scripts]# /usr/local/mysql56/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/mysqldata/node1
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/mysql56/scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at /usr/local/mysql56/scripts/mysql_install_db line 42.
解决办法:安装perl依赖包:
`yum install perl perl-devel
yum install 'perl(Data::Dumper)`
错误信息2:[ERROR] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
解决办法是创建mysql用户并将mysql用户分到mysql用户组:
`groupadd mysql //mysql用户组
useradd -r -g mysql mysql //mysql用户`
3、配置my.cnf文件以及启动
basedir = /usr/local/mysql56
datadir = /mysqldata/node1
port = 5000
server_id = 5000
socket = /tmp/mysql.sock
log-bin = /mysqldata/node1/mysql-bin
expire_logs_days = 10
max_binlog_size = 100m
binlog_format=mixed
[mysqld_safe]
ledir = /usr/local/mysql56/bin
nice = 0
user = mysql
--datadir=/mysqldata/node1`
安装中遇到小插曲
安装过程中,遇到的错误提示信息1,错误发生原因是缺少perl依赖包:
[root@VM_85_23_centos scripts]# /usr/local/mysql56/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/mysqldata/node1
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/mysql56/scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at /usr/local/mysql56/scripts/mysql_install_db line 42.
解决办法:安装perl依赖包:
`yum install perl perl-devel
yum install 'perl(Data::Dumper)`
错误信息2:[ERROR] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
解决办法是创建mysql用户并将mysql用户分到mysql用户组:
`groupadd mysql //mysql用户组
useradd -r -g mysql mysql //mysql用户`
3、配置my.cnf文件以及启动
basedir = /usr/local/mysql56
datadir = /mysqldata/node1
port = 5000
server_id = 5000
socket = /tmp/mysql.sock
log-bin = /mysqldata/node1/mysql-bin
expire_logs_days = 10
max_binlog_size = 100m
binlog_format=mixed
[mysqld_safe]
ledir = /usr/local/mysql56/bin
nice = 0
user = mysql
然后就可以启动mysql了。
启动mysql使用:/usr/local/mysql56/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/mysqldata/node1
登入mysql 使用mysql -uroot --socket=/tmp/mysql.sock
马克一下,第一次进入系统是没有密码的,所以登入以后可以修改密码。
如果一切都顺利,应该就可以启动mysql。