今天公司新买了两台阿里云的服务器是CentOS7 64位的,要重新部署环境,我们的环境是:tomact+zookeeper+redis+mysql+dubbo。于是下午3点多开始搞,jdk、tomact、zookeeper、redis都没碰到什么问题,这种简单安装基本上网上百度一大堆完全能解决需求。 轮到mysql问题来了,首先 百度的是“linux 安装mysql”出来的一串让你去官网下载Linux-generic 版本,然后手动安装解压安装,配置一些配置文件的,包括百度百科和百度知道都是这么说,照着做了之后,启动msyql服务,报错:
/usr/local/mysql/mysql-5.6.37-linux-glibc2.12-x86_64/bin/mysqld: Table 'mysql.plugin' doesn't exist 2017-08-30 18:38:02 24241 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 2017-08-30 18:38:02 24241 [Note] InnoDB: Using atomics to ref count buffer pool pages 2017-08-30 18:38:02 24241 [Note] InnoDB: The InnoDB memory heap is disabled 2017-08-30 18:38:02 24241 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2017-08-30 18:38:02 24241 [Note] InnoDB: Memory barrier is not used 2017-08-30 18:38:02 24241 [Note] InnoDB: Compressed tables use zlib 1.2.3 2017-08-30 18:38:02 24241 [Note] InnoDB: Using Linux native AIO 2017-08-30 18:38:02 24241 [Note] InnoDB: Using CPU crc32 instructions 2017-08-30 18:38:02 24241 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2017-08-30 18:38:02 24241 [Note] InnoDB: Completed initialization of buffer pool 2017-08-30 18:38:02 24241 [Note] InnoDB: Highest supported file format is Barracuda. 2017-08-30 18:38:02 24241 [Note] InnoDB: Log scan progressed past the checkpoint lsn 49463 2017-08-30 18:38:02 24241 [Note] InnoDB: Database was not shutdown normally! 2017-08-30 18:38:02 24241 [Note] InnoDB: Starting crash recovery. 2017-08-30 18:38:02 24241 [Note] InnoDB: Reading tablespace information from the .ibd files... 2017-08-30 18:38:02 24241 [Note] InnoDB: Restoring possible half-written data pages 2017-08-30 18:38:02 24241 [Note] InnoDB: from the doublewrite buffer... InnoDB: Doing recovery: scanned up to log sequence number 1600607 2017-08-30 18:38:02 24241 [Note] InnoDB: Starting an apply batch of log records to the database... InnoDB: Progress in percent: 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 InnoDB: Apply batch completed 2017-08-30 18:38:03 24241 [Note] InnoDB: 128 rollback segment(s) are active. 2017-08-30 18:38:03 24241 [Note] InnoDB: Waiting for purge to start 2017-08-30 18:38:03 24241 [Note] InnoDB: 5.6.37 started; log sequence number 1600607 2017-08-30 18:38:03 24241 [Note] Server hostname (bind-address): '*'; port: 3306 2017-08-30 18:38:03 24241 [Note] IPv6 is available. 2017-08-30 18:38:03 24241 [Note] - '::' resolves to '::'; 2017-08-30 18:38:03 24241 [Note] Server socket created on IP: '::'. 2017-08-30 18:38:03 24241 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist网上百度错误原因,不行。 然后觉得可能是5.7.19可能高了,就下载了5.6,可是启动还是同样上面的原因,找了半天没找到原因,搞的头疼。算了只能放弃。 于是选择了yum指令安装,用的是yum install mysql* ,没有安装成功,重新查看了yum源中mysql的版本 yum -y list mysql*,问题来了没有找到mysql service的源,百度了一下,CentOS7的yum源中默认好像是没有MySQL的。为了解决这个问题,我们必须先下载mysql的repo源,于是有了解决方案: 1. 下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm2.安装mysql-community-release-el7-5.noarch.rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm3.安装mysql
sudo yum install mysql-server此时会停顿两次让你选择 一直y就行了 4.文件给权限 安装完成后要求mysql重置密码,但在之前必须将/var/lib/mysql 访问权限给了(yum 安装时默认文件夹) 如果,不给这个时候会报错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2) 给权限:
chown -R root:root /var/lib/mysql5.重置密码 因为上一步将文件的访问权限修改了,因此先重启服务
service mysqld restart进入mysql:mysql -u root 会进入mysql mysql > use mysql; mysql > update user set authentication_string=password('123123') where user='root'; mysql > exit; 此时mysql,已经安装完成 中间可能会有: ERROR 1017:Can t find file 这类的错误,根本原因就是文件读取权限的问题,只要将权限付给当前用户就行,当然如果是root,直接给root就好 6.开放默认端口3306 首先用的是:service iptables start/stop, 结果报错:Unit iptables.service failed to load: No such file or directory. 无比蛋疼之下,突然想到了在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理 所以改用了firewall-cmd指令。 先查看防火墙是否开启:systemctl status firewalld 防火墙提示dead状态, 开启防火墙:systemctl start firewalld 再次查看发现防火墙提示已经激活, 开启3306端口:firewall-cmd --zone=public --add-port=3306/tcp --permanent 刷新:firewall-cmd --reload 查看3306端口是否开启:firewall-cmd --query-port=3306/tcp 给的提示是yes 表示开启成功。 7.navicat 尝试远程连接 远程连接的时候蛋疼的又出错了。。 报的错是:Access 。。。什么的意思密码是对的可是连接不对, 这个错误原因是你的mysql没有开启远程连接, 指令:mysql -u root进入mysql 赋权:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123321' WITH GRANT OPTION; 刷新:flush privileges navicat 重新test测试 提示成功! **如果没有成功,很可能是你的数据库里mysql系统安装的这个库下user表数据有问题,可以进去看看,一般完成之后是4条数据,找个好的先把新的删掉在插入。 mysql安装成功。。。。 一路的坑,搞了几个小时才搞完,给我最深的感悟: 1、能简单搞的千万别弄复杂,本来用yum指令直接安装这么方便,偏偏去搞了手动安装的。 2、百度上面的资料一定要选最新的,老版本的都不见得能用了,不然太浪费时间,后面出问题自己都不知道怎么搞。 3、搜索Linux这种开源的系统资料,一定要带上版本关键字,如果我一开始搜索 Linux centOS7 下安装mysql就可以避免进入第一次那么复杂的手动安装。 以上都是今天切身体会踩到的坑,如果错误欢迎指正!如果有博友也是碰到这些问题,可以留言互相讨论,谢谢!