centos7 yum方式安装mysql5.6

1, 安装带有可用的mysql5系列社区版资源的rpm包

rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

2,  查看当前可用的mysql安装资源 yum repolist enabled | grep "mysql.*-community.*"

[root@MiWiFi-RM1800-srv ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64       MySQL Connectors Community           175
mysql-tools-community/x86_64            MySQL Tools Community                120
mysql56-community/x86_64                MySQL 5.6 Community Server           564

 3, 直接使用yum的方式安装MySQL

yum -y install mysql-community-server

4, 查看mysql版本  mysql -V

[root@MiWiFi-RM1800-srv ~]# mysql -V
mysql  Ver 14.14 Distrib 5.6.50, for Linux (x86_64) using  EditLine wrapper

5, mysql配置文件路径:/etc/my.cnf

[root@MiWiFi-RM1800-srv etc]# vi m
machine-id                man_db.conf               modules-load.d/           my.cnf
magic                     mke2fs.conf               motd                      my.cnf.d/
makedumpfile.conf.sample  modprobe.d/               mtab      

6, 启动和停止服务

service mysql start  --启动
service mysql stop  --关闭
service mysql restart  --重启

7, 初始化mysql   mysql_secure_installation  (按照提示一步一步完成, 可重复执行,第二次需要输入第一次设置的密码)

[root@MiWiFi-RM1800-srv etc]# 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远程登录
 ... Success!

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] n  ##是否移除test库
 ... skipping.

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...

8, 登录mysql  mysql -u用户名 -p密码

[root@MiWiFi-RM1800-srv etc]# mysql -uroot -p12345678
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.6.50 MySQL Community Server (GPL)

9, 选择数据库,执行sql

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        ||
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

mysql> select * from user;

猜你喜欢

转载自blog.csdn.net/gpweixing/article/details/111185489
今日推荐