Linux的centos7系统安装MySQL数据库软件与配置授权远程登录

文章类别 in linux

安装

  1. yum install mysql

  2. yum install mysql-devel

  3. wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-release-el7-5.noarch.rpm yum install mysql-community-server

检查是否安装成功

  1. 重启mysql服务: service mysqld restart
  2. 登入mysql(刚安装完是没有密码的): mysql -u root

如果显示以下信息说明安装完成:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

设置数据库密码

设置密码为root:

set password for 'root'@'localhost' =password('password');

下次登录mysql时需要密码:

[root@wistbean ~]# mysql -u root -p
Enter password: 

配置字符编码:

vi /etc/my.cnf

添加:

[mysql]
default-character-set =utf8

配置远程连接:

 grant all privileges on *.* to root@'%'identified by 'password';

意思是通过root账号和root密码可以使用所有的MySQL权限。这样子就可以通过远程登录这个MySQL了!