系统环境:CentOS 7 最小化安装版
rpm-qd | grep -i mysql #检查mysqlrpm相关的包是否安装,如安装则删除。
rpm-ivh http://repo.mysql.com/yum/mysql-5.5-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpm #导入mysql5.6的源
yumrepolist enabled | grep "mysql.*-community.*" #查看当前可用的mysql安装资源
yuminstall mysql-server mysql-client mysql-devel #安装mysql
mysqladmin–version #查看mysql版本信息
systemctlstart mysqld #开启mysql服务
systemctlenable mysqld #设置mysql开机启动
systemctlstatus mysqld #查看mysql运行状态
mysql_secure_installation #重置密码
NOTE:RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
Inorder to log into MySQL to secure it, we'll need the current
passwordfor the root user. If you've justinstalled MySQL, and
youhaven't set the root password yet, the password will be blank,
soyou should just press enter here.
Entercurrent password for root (enter for none):
OK,successfully used password, moving on...
Settingthe root password ensures that nobody can log into the MySQL
rootuser without the proper authorisation.
Youalready have a root password set, so you can safely answer 'n'.
Changethe root password? [Y/n] y #更改root密码
Newpassword:
Re-enternew password:
Passwordupdated successfully!
Reloadingprivilege tables..
... Success!
Bydefault, a MySQL installation has an anonymous user, allowing anyone
tolog into MySQL without having to have a user account created for
them. This is intended only for testing, and tomake the installation
goa bit smoother. You should remove thembefore moving into a
productionenvironment.
Removeanonymous users? [Y/n] y #删除匿名用户
... Success!
Normally,root should only be allowed to connect from 'localhost'. This
ensuresthat someone cannot guess at the root password from the network.
Disallowroot login remotely? [Y/n] n #禁止root远程登陆
... skipping.
Bydefault, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, andshould be removed
beforemoving into a production environment.
Removetest database and access to it? [Y/n] y #删除test数据库
- Dropping test database...
ERROR1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reloadingthe privilege tables will ensure that all changes made so far
willtake effect immediately.
Reloadprivilege tables now? [Y/n] y #刷新权限
... Success!
Alldone! If you've completed all of theabove steps, your MySQL
installationshould now be secure.
Thanksfor using MySQL!
Cleaningup...
mysql-u root -p #以root身份登陆