centos7yum方式安装mysql5.6版本数据库
注:出这个版本的安装方式使用因为 centos自带mariadb
其实yum方式安装是可以不用删除mariadb的,安装MySQL会覆盖掉之前已存在的mariadb
1:下载源文件
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
2:判断当前centos系统中是否有已存在的mysql,有则卸载即可
yum list installed | grep mysql
#删除系统自带的mysql
yum -y remove mysql-libs.x86_64
#卸载后再用全局查找,查找出残留的文件等信息,继续删除
find / -name mysql
#rm -rf 自行删除查询出来的目录,若没有则无需删除
由于这个mysql的yum源服务器在国外,所以下载速度会比较慢,mysql5.6只有79M大,而mysql5.7就有182M。(其实就是你服务器垃圾,没别的)
3:安装mysql-community-release-el7-5.noarch.rpm包
rpm -ivh mysql57-community-release-el7-7.noarch.rpm
安装完这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo
#进入/etc/yum.repos.d/
cd /etc/yum.repos.d/
vim mysql-community.repo
用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件
yum repolist all | grep mysql
yum install mysql-server -y
# 加入开机自启动
systemctl enable mysqld
# 启动mysql服务进程
systemctl start mysqld
# 查看mysql服务进程
systemctl status mysqld
4:安装完毕后 mysql会生成一个随机密码 命令查看:
cat /var/log/mysqld.log |grep password
5:查看是否可以用密码登录:
mysql -uroot -p?j/6P-ou#D<1
6:初始化数据库(请注意如下设置)
mysql_secure_installation
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we"ll need the current
password for the root user. If you"ve just installed MySQL, and
you haven"t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y #是否设置root密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y #是否删除匿名用户
... Success!
Normally, root should only be allowed to connect from "localhost". This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n #是否禁止root用户远程登录
... skipping.
By default, MySQL comes with a database named "test" that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y #是否删除test数据库
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can"t drop database "test"; database doesn"t exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y #是否刷新权限配置生效
... Success!
All done! If you"ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
6:远程连接mysql、Navicat等工具连接的时候、就是远程连接、而不是登陆的账号密码了。
若远程连接账号密码都是对的、但是连接不上、可能就是防火墙没有添加3306端口、添加上就OK了
配置:
登陆mysql
mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO "myuser"@"%" IDENTIFIED BY "mypassword" WITH GRANT OPTION;
mysql> flush privileges;
mysql> exit;
以上是 centos7yum方式安装mysql5.6版本数据库 的全部内容, 来源链接: utcz.com/z/534459.html