- 写这个blog原因:由于最近学习Centos 7,需要部署运行环境,但是百度时候找到的blog要么版本比较旧所以和现在mysql安装包有些出入。经过自己不断测试,终于自己安装好mysql了,所以现在分享自己的成果,顺带可以mark 一下。
[root@centos-linux ~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64
[root@centos-linux ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps
2.到mysql官网下载liunx 64位版本,或者使用liunx指令网络安装官网下载:http://www.mysql.com/ 我这里分享我自己在mysql网站下载的最新版本:链接: http://pan.baidu.com/s/1kVhmHWb 密码: 2ikt 下载后,放置到Centos 服务器的/usr/local/ 文件夹上解压 :
[root@centos-linux ~]# lsmysql-5.7.16-1.el7.x86_64.rpm-bundle.tar解压后,出现如下文件:
[root@centos-linux ~]# tar xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
mysql-community-devel-5.7.16-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm
mysql-community-libs-5.7.16-1.el7.x86_64.rpm
mysql-community-common-5.7.16-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm
mysql-community-test-5.7.16-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm
mysql-community-server-5.7.16-1.el7.x86_64.rpm
mysql-community-client-5.7.16-1.el7.x86_64.rpm
mysql-community-embedded-5.7.16-1.el7.x86_64.rpm
依次执行(几个包有依赖关系,所以执行有先后)下面命令安装:
[root@centos-linux ~]# rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm
数据库初始化:在 Liunx 系统中,为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你是以 root 身份运行 mysql 服务,需要执行下面的命令初始化
[root@centos-linux ~]# mysqld --initialize --user=mysql
如果是以 mysql 身份运行,则可以去掉 --user 选项。另外 --initialize 选项默认以“安全”模式来初始化,则会为 root 用户生成一个密码并将该密码标记为过期,登陆后你需要设置一个新的密码,而使用 --initialize-insecure 命令则不使用安全模式,则不会为 root 用户生成一个密码。这里演示使用的 --initialize 初始化的,会生成一个 root 账户密码,密码在log文件里
[root@localhost local]# cat /var/log/mysqld.log
2016-11-18T05:17:06.439015Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-11-18T05:17:06.619744Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-11-18T05:17:06.656070Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-11-18T05:17:06.715702Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3f94e95c-ad4e-11e6-ac8b-000c29994ce5.
2016-11-18T05:17:06.716475Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-11-18T05:17:06.717114Z 1 [Note] A temporary password is generated for root@localhost: <.xOzij-F2vr
红色highlight地方就是root账户下生成的随机密码。
启动mysql服务器:
[root@centos-linux ~]# systemctl start mysqld
[root@centos-linux ~]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.13Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
修改 root 密码该密码被标记为过期了,如果想正常使用还需要修改密码mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.以前的 password()函数将会被抛弃,官方建议使用下面的命令来修改密码mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '
不过要注意mysql 5.7 设定密码和之前版本密码不能太简单,详情请看这里解释:https://blog.laily.net/archives/571/
设置root外网ip访问,并对其授权:创建一个普通用户 sa ,密码是 some_passCREATEUSER'sa'@'%'IDENTIFIEDBY'some_pass';给这个用户授予 SELECT,INSERT,UPDATE,DELETE 的远程访问的权限,这个账号一般用于提供给实施的系统访问GRANTSELECT,INSERT,UPDATE,DELETEON *.*TO'sa'@'%';创建一个管理员用户 admin 账号 ,密码是 some_passCREATEUSER'admin'@'%'IDENTIFIEDBY'some_pass';给这个用户授予所有的远程访问的权限。这个用户主要用于管理整个数据库、备份、还原等操作。GRANT ALL ON *.*TO'admin'@'%';使授权立刻生效flushprivileges;
启动mysql 服务器指令:启动 MySQL Serversystemctlstart mysqld查看 MySQL Server 状态systemctl status mysqld关闭 MySQL Serversystemctlstop mysqld
防火墙设置:(预防iP可以ping接,但是navicat并不能连接的情况)远程访问 MySQL, 需开放默认端口号 3306.
还有其他设置与补充可以查阅这篇文章:http://www.centoscn.com/mysql/2016/0315/6844.html