`
cnjarchen
  • 浏览: 41746 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

centos7自定义安装mysql5.7

阅读更多

1.查找卸载原有的mysql

方法1

rpm -qa|grep mysql

rpm -e 文件名

 

方法2

yum list installed mysql*

yum remove mysql mysql-devel mysql-server mysql-libs compat-mysql51

 

方法3

find / -name mysql

然后rm -rf 文件

 

 

2.下载安装包
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

(若报-bash: wget: command not found,则表明没有安装wget,需要安装,安装命令如下:yum -y install wget)

 

3.解压安装包并修改文件名

tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /data/my/

mv mysql-5.7.17-linux-glibc2.5-x86_64/  mysql5.7

创建数据,日志文件夹

mkdir /data/my/mysql5.7/data
mkdir /data/my/mysql5.7/logs

 

4.配置

根据实际情况修改附件中的my.cnf覆盖/etc/my.cnf

 

5.将mysql服务加入到linux系统服务中

将安装目录中support-files/mysql.server cp 到/etc/init.d/mysql,注意修改文件中的basedir和datadir

 

6.初始化mysql

 cd /data/my/mysql5.7/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize

初始化中如出现 error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

  //安装后再初始化就OK了

yum install -y libaio

查看初始密码

cat /data/mysql/mysql.err

 

7.启动mysql

./mysqld_safe --user=root &

初始化后会生成一个临时密码 root@localhost::*******,在my.cnf里面配置的日志文件中可查看
然后检查mysql是否启动
ps -ef|grep mysql

 

注意可能会遇到:does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information

 
解决方法:
在MySQL 5.7中,安全性提升,要求切换到软件安装目录,来启动数据库
[root@localhost ~]# cd /mysql_software_57/
[root@localhost mysql_software_57]# bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 25341

 

7.修改密码并设置远程可连接

 进入客户端

./mysql -uroot -p

Enter password:输入临时密码

 

修改密码
mysql> set password=password('newpassword');

 

将root用户的主机改为%

mysql>use mysql;

mysql>select host, user from user;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

 

设置远程访问账号:grant all privileges on . to 远程访问用户名@’%’ identified by ‘用户密码’;
mysql> grant all privileges on *.* to root@'%' identified by 'newpassword';
刷新:
mysql> flush privileges;

退出mysql

mysql> exit;

// Linux关闭MySQL的命令
$mysql_dir/bin/mysqladmin -uroot -p shutdown

 

8.设置开机自启动

先赋权

chmod 777 /etc/init.d/mysql

chmod -R 777 /data/my/mysql5.7
添加服务mysql
chkconfig --add mysql
设置服务为自启动
chkconfig mysql on

最后重启服务器试试效果

reboot

 

 参考:https://www.cnblogs.com/ivictor/p/6846017.html#conclusion

            http://blog.csdn.net/yougoule/article/details/56680952

            https://blog.csdn.net/carefree2005/article/details/113313468

            https://blog.csdn.net/renqinglei1991/article/details/129747033

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics