MySQL5.6 安装(CentOS7 RPM方式安装)
一、下载MySql
1、官网下载地址:https://dev.mysql.com/downloads/mysql/
2、选择老版本mysql
3、根据具体需求选要下载的mysql 版本
4、下载 server和client 的rpm安装包
5、不需要登录直接下载即可
二、安装MySQL
1、centos7 会自带mariadb(mysql 完全开源版本)相关的组件,首先将至卸载。
1.1、查看:rpm -qa | grep mariadb
1.2、卸载:rpm -e --nodeps mariadb-libs (没有消息就是最好的消息)
2、安装mysql,准备好之前下载的安装包
2.1、安装执行 server :rpm -ivh MySQL-server-5.6.47-1.el7.x86_64.rpm
注意:此处有坑会报错,安装是失败:
error: Failed dependencies:
perl(Data::Dumper) is needed by MySQL-server-5.6.47-1.el7.x86_64
解决:在查找资料后发现,需要安装autoconf,使用yum安装即可解决:yum -y install autoconf
再次执行安装命令可正常安装完成:
注意观察安装结束后的提示信息:
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2020-01-16 16:23:08 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-01-16 16:23:08 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-01-16 16:23:08 0 [Note] /usr/sbin/mysqld (mysqld 5.6.47) starting as process 4682 ...
2020-01-16 16:23:08 4682 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-01-16 16:23:08 4682 [Note] InnoDB: The InnoDB memory heap is disabled
2020-01-16 16:23:08 4682 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-01-16 16:23:08 4682 [Note] InnoDB: Memory barrier is not used
2020-01-16 16:23:08 4682 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-01-16 16:23:08 4682 [Note] InnoDB: Using Linux native AIO
2020-01-16 16:23:08 4682 [Note] InnoDB: Using CPU crc32 instructions
2020-01-16 16:23:08 4682 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-01-16 16:23:08 4682 [Note] InnoDB: Completed initialization of buffer pool
2020-01-16 16:23:08 4682 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2020-01-16 16:23:08 4682 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2020-01-16 16:23:08 4682 [Note] InnoDB: Database physically writes the file full: wait...
2020-01-16 16:23:09 4682 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2020-01-16 16:23:09 4682 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2020-01-16 16:23:09 4682 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2020-01-16 16:23:09 4682 [Warning] InnoDB: New log files created, LSN=45781
2020-01-16 16:23:09 4682 [Note] InnoDB: Doublewrite buffer not found: creating new
2020-01-16 16:23:09 4682 [Note] InnoDB: Doublewrite buffer created
2020-01-16 16:23:09 4682 [Note] InnoDB: 128 rollback segment(s) are active.
2020-01-16 16:23:09 4682 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-01-16 16:23:09 4682 [Note] InnoDB: Foreign key constraint system tables created
2020-01-16 16:23:09 4682 [Note] InnoDB: Creating tablespace and datafile system tables.
2020-01-16 16:23:09 4682 [Note] InnoDB: Tablespace and datafile system tables created.
2020-01-16 16:23:09 4682 [Note] InnoDB: Waiting for purge to start
2020-01-16 16:23:09 4682 [Note] InnoDB: 5.6.47 started; log sequence number 0
2020-01-16 16:23:09 4682 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2020-01-16 16:23:09 4682 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
A random root password has been set. You will find it in '/root/.mysql_secret'.
2020-01-16 16:23:09 4682 [Note] Binlog end
2020-01-16 16:23:09 4682 [Note] InnoDB: FTS optimize thread exiting.
2020-01-16 16:23:09 4682 [Note] InnoDB: Starting shutdown...
2020-01-16 16:23:11 4682 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2020-01-16 16:23:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-01-16 16:23:11 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-01-16 16:23:11 0 [Note] /usr/sbin/mysqld (mysqld 5.6.47) starting as process 4704 ...
2020-01-16 16:23:11 4704 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-01-16 16:23:11 4704 [Note] InnoDB: The InnoDB memory heap is disabled
2020-01-16 16:23:11 4704 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-01-16 16:23:11 4704 [Note] InnoDB: Memory barrier is not used
2020-01-16 16:23:11 4704 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-01-16 16:23:11 4704 [Note] InnoDB: Using Linux native AIO
2020-01-16 16:23:11 4704 [Note] InnoDB: Using CPU crc32 instructions
2020-01-16 16:23:11 4704 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-01-16 16:23:11 4704 [Note] InnoDB: Completed initialization of buffer pool
2020-01-16 16:23:11 4704 [Note] InnoDB: Highest supported file format is Barracuda.
2020-01-16 16:23:11 4704 [Note] InnoDB: 128 rollback segment(s) are active.
2020-01-16 16:23:11 4704 [Note] InnoDB: Waiting for purge to start
2020-01-16 16:23:11 4704 [Note] InnoDB: 5.6.47 started; log sequence number 1625977
2020-01-16 16:23:11 4704 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2020-01-16 16:23:11 4704 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-01-16 16:23:11 4704 [Note] Binlog end
2020-01-16 16:23:11 4704 [Note] InnoDB: FTS optimize thread exiting.
2020-01-16 16:23:11 4704 [Note] InnoDB: Starting shutdown...
2020-01-16 16:23:12 4704 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
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
2.2、安装client:rpm -ivh MySQL-client-5.6.47-1.el7.x86_64.rpm
2.3、检查是否安装成功:
mysqladmin --version (查看mysql 版本信息)
查看mysql 用户和用户组:cat /etc/passwd | grep mysql 和 cat /etc/group | grep mysql
三、启停MySQL
1、启动、关闭、重启、查看服务状态
systemctl start mysql 、systemctl restart mysql、systemctl stop mysql 、systemctl status mysql
2、设置mysql自启动
centos7 安装mysql后自动添加了自动启动mysql,无需特殊配置
四、登录mysql,重置密码,设置远程访问权限
1、查看随机数密码并登录mysql
随机密码存储位置在安装完毕的提示信息中有提示:
2、使用随机密码登录
mysql -uroot -p
3、修改密码
使用随机密码登录后无法进行数据库操作,需要修改密码
set password for [email protected]=password('123456');
之后使用设置的密码可以在本地登录
4、修改远程访问密码
修改远程访问密码及访问ip:grant all privileges on *.* to [email protected]'%' identified by '123456';
刷新授权列表:flush privileges;
注意:关闭防火墙或开放3306端口,否则远程无法访问
1、关闭防火墙:systemctl stop firewalld.service
2、开发3306端口:firewall-cmd --zone=public --add-port=3306/tcp --permanent