因为我自己安装软件的时候,大部分都是采用本地的安装包,所以需要上传文件,因此需要安装lrzsz,如未安装,参考:Linux环境搭建(lrzsz)。
MySQL5.6.33安装文件:
链接: https://pan.baidu.com/s/1r61WciXJLeTHqanwak7XMw 密码: 9j3k
安装:
##上传MySQL安装文件(安装文件建议放在/tmp目录下,便于清理)
cd /tmp && rz
##解压安装文件,并移动文件到/usr/local,修改名称为mysql
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz && mv mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
##添加用户组并添加用户root到用户组mysql
groupadd mysql && useradd -r -g root mysql
##创建MySQL文件目录(数据存储目录)
cd /usr/local/mysql && mkdir ./data/mysql
##修改文件的所有者,这样做的目的是为了安全,不是所有的人都能碰MySQL的文件的
chown -R root:mysql ./
##执行安装
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
##添加开机启动(把启动脚本放到开机初始化目录)
cp support-files/mysql.server /etc/init.d/mysqld
##设置读写权限
chmod 755 /etc/init.d/mysqld
#修改启动脚本
vi /etc/init.d/mysqld
##修改项:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
##指定配置文件(这一步不可少,否则会有下面问题)
cp support-files/my-default.cnf /etc/my.cnf
##启动服务
service mysqld start
##授权远程访问并设置密码
./bin/mysql -uroot && use mysql && GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION && FLUSH PRIVILEGES
遇到的问题:
##执行编译安装时报如下异常
[root@VM_0_17_centos mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
##原因是缺少Data:dumper模块,解决方法如下
yum -y install autoconf //此包安装时会安装Data:Dumper模块
##启动服务时报如下异常
[root@VM_0_17_centos support-files]# service mysqld start
Starting MySQL.touch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directory
chmod: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
touch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directory
chown: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
/usr/local/mysql//bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory
/usr/local/mysql//bin/mysqld_safe: line 166: /var/log/mariadb/mariadb.log: No such file or directory
touch: cannot touch '/var/log/mariadb/mariadb.log': No such file or directory
chown: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
chmod: cannot access '/var/log/mariadb/mariadb.log': No such file or directory
/usr/local/mysql//bin/mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory
ERROR! The server quit without updating PID file (/var/lib/mysql/VM_0_17_centos.pid).
##原因是没有/var/log/mariadb/mariadb.log这个目录,如果没有指定配置文件,程序会默认找到/etc/my.cnf这个配置文件,解决方法如下
将/etc/my.cnf 删掉,再次启动
或者
cp support-files/my-default.cnf /etc/my.cnf,再次启动