centos6.5安装MySQL5.7
将mysql安装包解压到指定目录,命令如下:
tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local
进入/usr/local目录:
cd /usr/local
为mysql安装目录创建软链接:
ln -s mysql-5.7.18-linux-glibc2.5-x86_64 mysql
为centos添加mysql用户组和mysql用户(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限):
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
进入安装mysql软件的目录,命令如下:
cd /usr/local/mysql
修改当前目录拥有者为新建的mysql用户,命令如下:
chown -R mysql:mysql ./
安装mysql,命令如下:
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
安装完成,将随机生成的登录密码记录下来
开启mysql服务,命令如下:
./support-files/mysql.server start
将mysql进程放入系统进程中,命令如下:
cp support-files/mysql.server /etc/init.d/mysqld
重新启动mysql服务,命令如下:
service mysqld restart
使用随机密码登录mysql数据库,命令如下:
mysql -u root -p
等待系统提示,输入随机密码,即可登录
进入mysql操作行,为root用户设置新密码:
alter user 'root'@'localhost' identified by '123456';
设置允许远程连接数据库,命令如下:
update user set user.Host='%' where user.User='root';
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY
'mypassword' WITH GRANT OPTION;
刷新权限,命令如下:
flush privileges;
遇到的问题。。。
[root@bigdata3 mysql]# ./support-files/mysql.server start
Starting MySQL.2018-03-01T09:10:01.458897Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/var/lib/mysql/bigdata3.pid).
解决方法
mv /etc/my.cnf /etc/my.cnf.bak