美文网首页
2018-06-09 centos下安装MySQL5.7过程

2018-06-09 centos下安装MySQL5.7过程

作者: 胡袁强先生 | 来源:发表于2018-06-09 19:45 被阅读0次

    1.mysql5.7.17安装在/usr/local/mysql目录里面,也可以安装在其他地方 (安装包最好与Linux系统一样,eg;32位的就是“mysql-5.7.17-linux-glibc2.5-i686.tar.gz”,官网可下载)

    mkdir /usr/local/mysql

    2.解压并复制

    tar -xvf mysql-5.7.17-linux-glibc2.5-i686.tar.gz

    mv mysql-5.7.17-linux-glibc2.5-i686.tar.gz/* /usr/local/mysql

    3.创建data目录(很重要!)

    mkdir /usr/local/mysql/data  

    4.创建mysql用户和修改权限

    groupadd mysql  

    chown -R mysql.mysql /usr/local/mysql/  

    如果出现  chown: invalid user: `mysql.mysql'   则需要加上  useradd -r -g mysql mysql 这个命令

    5 查看系统中是否已安装 MySQL 服务:

    rpm -qa | grep mysql

    yum list installed | grep mysql

    6 如果已安装则删除 MySQL 及其依赖的包:

    yum -y remove mysql-libs.x86_64

    8 初始化数据库 

    [root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/  

    2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize  

    2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:  

    2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead  

    2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)  

    2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000) 

    9. 复制配置文件到 /etc/my.cnf

    cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y) 

    如果  support-files  文件夹下面没有  my-default.cnf 则不需要,默认 /etc/my.cnf是有这个文件的

    如果 /etc/my.cnf 没有这个文件夹,则需要从其他地方拷贝过来  vim /etc/my.cnf.rpmsave  也可以命名为这样的

    10.启动mysql

    service mysqld start   

    ps -ef        #查看是启动

    9.查看初始化自动生成的密码:   cat /root/.mysql_secret  (记住并复制下来,等会登陆mysql需要) 这个地方如果没有记录下来后面的操作基本上进入不了MySQL命令

    10.进入mysql:bin/mysql -uroot -p  (把刚刚复制的密码粘贴上来)

    11.登录后重置root密码

    mysql> SET PASSWORD FOR 'root'@localhost=password('123456');

    Query OK, 0 rows affected, 1 warning (0.00 sec)

    设置远程访问权限,如果不设置远程访问权限,远程是不能访问你的数据库的

    mysql> use mysql;

    Reading table information for completion of table and column names

    You can turn off this feature to get a quicker startup with -A

    Database changed

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

    Query OK, 1 row affected (0.00 sec)

    Rows matched: 1  Changed: 1  Warnings: 0

    mysql> select host, user from user;

    [root@localhost mysql]# /etc/init.d/mysqld restart

    12 重启MySQL

    [root@localhost mysql]# /etc/init.d/mysqld restart 

    13 连接远程数据库

    [root@localhost mysql]# service iptables status

    如果开启网络防火墙,需要关闭网络防火墙

    [root@localhost mysql]# service iptables stop

    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

    iptables: Flushing firewall rules:                        [  OK  ]

    iptables: Unloading modules:                              [  OK  ]

    [root@localhost mysql]#

    完毕!!!!!!!!!!!!

    相关文章

      网友评论

          本文标题:2018-06-09 centos下安装MySQL5.7过程

          本文链接:https://www.haomeiwen.com/subject/tjfxeftx.html