《阿里云 Centos7.3安装mysql5.7.18 rpm安装Mysql实例》要点:
本文介绍了阿里云 Centos7.3安装mysql5.7.18 rpm安装Mysql实例,希望对您有用。如果有疑问,可以联系我们。
CentOS7默认安装MariaDB而不是MySQL,而且yum服务器上也移除了MySQL相关的软件包.因为MariaDB和MySQL可能会冲突,故先卸载MariaDB.MYSQL入门
1、安装新版mysql之前,我们需要将系统自带的mariadb-lib卸载
MYSQL入门
- [root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -qa | grep -i mariadb
- mariadb-libs-5.5.52-1.el7.x86_64
- [root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
MYSQL入门
2、到mysql的官网下载最新版mysql的rpm集合包:mysql-5.7.18-1.el6.x86_64.rpm-bundle.tarMYSQL入门
3、上传mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar到linux服务器,并解压tar包
MYSQL入门
- [root@iZwz94qazh62gk5ewl4ei2Z home]# mkdir mysql
- [root@iZwz94qazh62gk5ewl4ei2Z home]# tar -xf mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar -C mysql
- [root@iZwz94qazh62gk5ewl4ei2Z home]# cd mysql
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]# ll
- total 459492
- -rw-r--r-- 1 7155 31415 23618836 Mar 20 17:40 mysql-community-client-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 335496 Mar 20 17:40 mysql-community-common-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 3747352 Mar 20 17:40 mysql-community-devel-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 39086508 Mar 20 17:40 mysql-community-embedded-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 135869292 Mar 20 17:40 mysql-community-embedded-devel-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 2177064 Mar 20 17:40 mysql-community-libs-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 1723180 Mar 20 17:40 mysql-community-libs-compat-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 159060212 Mar 20 17:41 mysql-community-server-5.7.18-1.el6.x86_64.rpm
- -rw-r--r-- 1 7155 31415 104881084 Mar 20 17:41 mysql-community-test-5.7.18-1.el6.x86_64.rpm
4、使用rpm -ivh命令进行安装MYSQL入门
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-common-5.7.18-1.el6.x86_64.rpm
- warning: mysql-community-common-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
- Preparing... ################################# [100%]
- Updating / installing...
- 1:mysql-community-common-5.7.18-1.e################################# [100%]
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-libs-5.7.18-1.el6.x86_64.rpm
- warning: mysql-community-libs-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
- Preparing... ################################# [100%]
- Updating / installing...
- 1:mysql-community-libs-5.7.18-1.el6################################# [100%]
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-client-5.7.18-1.el6.x86_64.rpm
- warning: mysql-community-client-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
- Preparing... ################################# [100%]
- Updating / installing...
- 1:mysql-community-client-5.7.18-1.e################################# [100%]
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-server-5.7.18-1.el6.x86_64.rpm
- warning: mysql-community-server-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
- Preparing... ################################# [100%]
- Updating / installing...
- 1:mysql-community-server-5.7.18-1.e################################# [100%]
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]#
上面几个包有依赖关系,执行有先后.MYSQL入门
使用rpm安装方式安装mysql,安装的路径如下:MYSQL入门
a 数据库目录
/var/lib/mysql/
b 配置文件
/usr/share/mysql(mysql.server命令及配置文件)
c 相关命令
/usr/bin(mysqladmin mysqldump等命令)
d 启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)MYSQL入门
e /etc/my.confMYSQL入门
5、 数据库初始化MYSQL入门
为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你的linux系统是以 root 身份运行 mysql 服务,需要执行下面的命令初始化
MYSQL入门
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysqld --initialize --user=mysql
MYSQL入门
如果是以 mysql 身份登录运行,则可以去掉 --user 选项.MYSQL入门
另外 --initialize 选项默认以“安全”模式来初始化,则会为 root 用户生成一个密码并将该密码标记为过期,登陆后你需要设置一个新的密码,MYSQL入门
而使用 --initialize-insecure 命令则不使用安全模式,则不会为 root 用户生成一个密码.MYSQL入门
这里演示使用的 --initialize 初始化的,会生成一个 root 账户密码,密码在log文件里,红色区域的就是自动生成的密码
MYSQL入门
- [root@iZwz94qazh62gk5ewl4ei2Z mysql]# cat /var/log/mysqld.log
- 2017-06-05T14:30:52.709474Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
- 2017-06-05T14:30:55.590590Z 0 [Warning] InnoDB: New log files created, LSN=45790
- 2017-06-05T14:30:56.000269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
- 2017-06-05T14:30:56.109868Z 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: 960c533e-49fb-11e7-91f2-00163e089fd2.
- 2017-06-05T14:30:56.116186Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
- 2017-06-05T14:30:56.116777Z 1 [Note] A temporary password is generated for root@localhost: :Wu?2QQutQwj
MYSQL入门
现在启动mysql数据库systemctl start mysqld.service(Centos7特有的启动方式)MYSQL入门
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# systemctl start mysqld.service
可以使用下面两个命令对mysql进行停止,启动和重启:MYSQL入门
启动:MYSQL入门
使用 service 启动:service mysqld start 使用 mysqld 脚本启动:/etc/inint.d/mysqld start 使用 safe_mysqld 启动:safe_mysqld&
停止:MYSQL入门
使用 service 启动:service mysqld stop 使用 mysqld 脚本启动:/etc/inint.d/mysqld stop mysqladmin shutdown
重启:MYSQL入门
使用 service 启动:service mysqld restart
使用 mysqld 脚本启动:/etc/inint.d/mysqld restart
连接数据库MYSQL入门
[root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysql -u root -p
Enter password:
密码输入: :Wu?2QQutQwjMYSQL入门
修改密码:MYSQL入门
set password = password('你的密码');
设置远程访问MYSQL入门
grant all privileges on *.* to 'root' @'%' identified by '123456'; flush privileges;
设置mysql开机启动MYSQL入门
- 加入到系统服务:
- chkconfig --add mysqld
- 自动启动:
- chkconfig mysqld on
- 查询列表:
- chkconfig
- 说明:都没关闭(off)时是没有自动启动.
MYSQL入门
转载请注明本页网址:
http://www.vephp.com/jiaocheng/5559.html