1、在服务器端开启远程访问
首先进入数据库,然后输入下面两个命令:grant all privileges on *.* to 'root'@'%' identified by 'password';flush privileges;第一个*是数据库,可以改成允许访问的数据库名称第二个 是数据库的表名称,代表允许访问任意的表root代表远程登录使用的用户名,可以自定义%代表允许任意ip登录,如果你想指定特定的IP,可以把%替换掉就可以了password代表远程登录时使用的密码,可以自定义flush privileges;这是让权限立即生效2、修改my.cnf配置文件这个是mysql的配置文件,如果你无标题文章找不到在哪里的话,可以输入find /* -name my.cnf 找到通过vim编辑该文件,找到bind-address = 127.0.0.1这一句,然后在前面加个#号注释掉,保存退出
3、重启服务
service mysql restart4、在本地远程连接在终端输入:mysql -h 服务器ip地址 -P 3306 -u root -p然后输入密码即可。root是第1点设置的用户名,密码也是第1点设置的密码Install 3 Packages (+2 Dependent packages)
Total download size: 171 MDownloading packages:mysql-community-server-5.7.10-1.el7.x86_64.rpm | 142 MB 00:03:42 mysql-community-libs-compat-5.7.10-1.el7.x86_64.rpm | 2.0 MB 00:00:03 mysql-community-libs-5.7.10-1.el7.x86_64.rpm | 2.2 MB 00:00:05 mysql-community-client-5.7.10-1.el7.x86_64.rpm | 24 MB 00:00:41 warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.10-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY00 ETA Public key for mysql-community-common-5.7.10-1.el7.x86_64.rpm is not installedmysql-community-common-5.7.10-1.el7.x86_64.rpm | 269 kB 00:00:01 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlImporting GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql57-community-release-el7-7.noarch (@/mysql57-community-release-el7-7.noarch) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlRunning transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : mysql-community-common-5.7.10-1.el7.x86_64 1/6 Installing : mysql-community-libs-5.7.10-1.el7.x86_64 2/6 Installing : mysql-community-client-5.7.10-1.el7.x86_64 3/6 Installing : mysql-community-server-5.7.10-1.el7.x86_64 4/6 Installing : mysql-community-libs-compat-5.7.10-1.el7.x86_64 5/6 Erasing : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 6/6 Verifying : mysql-community-server-5.7.10-1.el7.x86_64 1/6 Verifying : mysql-community-libs-compat-5.7.10-1.el7.x86_64 2/6 Verifying : mysql-community-common-5.7.10-1.el7.x86_64 3/6 Verifying : mysql-community-libs-5.7.10-1.el7.x86_64 4/6 Verifying : mysql-community-client-5.7.10-1.el7.x86_64 5/6 Verifying : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 6/6Installed: mysql-community-libs.x86_64 0:5.7.10-1.el7 mysql-community-libs-compat.x86_64 0:5.7.10-1.el7 mysql-community-server.x86_64 0:5.7.10-1.el7Dependency Installed: mysql-community-client.x86_64 0:5.7.10-1.el7 mysql-community-common.x86_64 0:5.7.10-1.el7Replaced: mariadb-libs.x86_64 1:5.5.44-2.el7.centosComplete![root@typecodes ~]# clear