码迷,mamicode.com
首页 > 数据库 > 详细

CentOS7下mysql安装

时间:2015-06-02 17:58:26      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

CentOS7下安装MySQL


--下载mysql
http://mirrors.sohu.com/mysql/MySQL-5.6/
http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar


一。准备工作
--下载后文件
MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar


--新建文件夹
mkdir /home/www/tar
mkdir /home/www/rpm


--上传文件至rpm包下解压
tar -xvf MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
...
MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-devel-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.24-1.linux_glibc2.5.x86_64.rpm

--把tar文件移至/home/www/tar
mv MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar /home/www/tar


二、开始安装
--开始安装(其中,v表示显示详细安装信息,h表示显示用#表示安装进度)
rpm -ivh MySQL-*


--看到如下信息已安装成功
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in ‘/root/.mysql_secret‘.
...
...
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings


备注:最新版的MySQL将随机生成一个root用户的密码,放在/root/.mysql_secret 文件中


--查看端口(默认3306)
[root@localhost init.d]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 192.168.1.110:22        192.168.1.119:50608     ESTABLISHED
tcp6       0      0 :::3306                 :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN


三、安装位置
用RPM进行安装的时候,MySQL下的子目录被分散开,分别放在了以下几个目录下:
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql // mysql启动配置脚本,其中只有一个叫mysql的可执行文件 与mysql有关
/var/lib/mysql // Mysql中的数据库存放目录
/var/lock/subsys/mysql
/usr/lib/mysql                  //  该文件夹下是mysql链接库
/usr/include/mysql //  mysql 头文件
/usr/share/mysql //  mysql 安装目录
/usr/bin // 其中有mysql的多个可执行程序,如mysql、mysql_config_editor、mysqlcheck、mysqladmin等


四、mysql停止与重启
/etc/rc.d/init.d/mysql restart
/etc/rc.d/init.d/mysql stop
/etc/rc.d/init.d/mysql start


五、错误排查
[root@localhost rpm]# mysql -uroot
--出现问题
(1)报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
--停止服务
/etc/rc.d/init.d/mysql stop
--安全模式进入mysql
[root@localhost rpm]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@localhost rpm]# mysql -u root mysql
--更改用户名
mysql> UPDATE user SET Password=PASSWORD(‘root‘) where User=‘root‘;
mysql> FLUSH PRIVILEGES;
mysql> quit
[root@localhost rpm]# mysql -uroot -p
mysql> show databases;
(2)报错:ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
--重新设置root密码
mysql> SET PASSWORD = PASSWORD(‘root‘);
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)


(3)navicat报错:Host ‘192.168.1.*‘ is not allowed to connect to this MySQL server
原因:mysql下user表中不允许外部链接
--临时把端口加入防火墙
firewall-cmd --permanent --zone=public --add-port=3306/tcp
systemctl restart firewalld.service
--更改host
[root@localhost rpm]# mysql -uroot -p
mysql> use mysql
mysql> select host, user from user;
+-----------------------+------+
| host                  | user |
+-----------------------+------+
| 127.0.0.1             | root |
| ::1                   | root |
| localhost             | root |
| localhost.localdomain | root |
+-----------------------+------+
4 rows in set (0.00 sec)
--更改localhost为%
mysql> update user set host = ‘%‘ where host=‘localhost‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host, user from user;
+-----------------------+------+
| host                  | user |
+-----------------------+------+
| %                     | root |
| 127.0.0.1             | root |
| ::1                   | root |
| localhost.localdomain | root |
+-----------------------+------+
4 rows in set (0.00 sec)
--重启mysql服务
/etc/rc.d/init.d/mysql restart

至此mysql已可以正常使用!


六、开机启动
使用命令:sbin/chkconfig --list,查看启动项
使用命令:sbin/chkconfig --add mysql,将mysql添加到开机启动项中:
使用命令:sbin/chkconfig --del mysql,将mysql从开机启动项中删除:



CentOS7下mysql安装

标签:

原文地址:http://blog.csdn.net/pa5201314/article/details/46331703

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!