CentOS下安装MySQL,Windows下使用Navicat for MySql连接

安装

查看有没有安装过:
          yum list installed mysql*
          rpm -qa | grep mysql*
 
查看有没有安装包:
          yum list mysql*
 
安装mysql客户端:
          yum install mysql
 
安装mysql 服务器端:
          yum install mysql-server
          yum install mysql-devel

启动&&停止

数据库字符集设置

          mysql配置文件/etc/my.cnf中的[mysqld]配置节中加入default-character-set=utf8

有时候配置文件可能在/usr/my.cnf中,如果还是找不到,使用以下命令查找:

find -name my.cnf

 方法:vi /etc/my.cnf,通过上下左右键移动光标,按字母“i”进入编辑状态,Shift + Insert 粘贴内容(我是通过Xshell操作的),按ESC键进入命令模式,输入“:wq”按回车键。


启动mysql服务:
          service mysqld start或者/etc/init.d/mysqld start
开机启动:
          chkconfig -add mysqld,查看开机启动设置是否成功chkconfig --list | grep mysql*
 
          mysqld             0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
停止:
          service mysqld stop

登录

创建root管理员:
          mysqladmin -u root password 123456
这个没有执行通过,提示:mysqladmin: Can't turn off logging; error: 'Access denied; you need the SUPER privilege for this operation'
登录:
          mysql -u root -p输入密码即可。
忘记密码:
          service mysqld stop
 
          mysqld_safe --user=root --skip-grant-tables

执行这条语句之后就不能再输入命令了,

输出:140616 19:23:09 mysqld_safe Logging to '/var/log/mysqld.log'.
140616 19:23:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

之后就停在那里不动,需要再开终端执行命令;
 
          mysql -u root
 
          use mysql;
 
          update user set password=password(’123456‘) where user=’root‘;
 
          flush privileges;  
  但是执行完这些命令没能解决Windows下使用Navicat for MySql连接不上的问题;

远程访问

开放防火墙的端口号,或关闭防火墙;
mysql增加权限:mysql库中的user表新增一条记录host为“%”,user为“root”。

这个测试也不管用;

Linux MySQL的几个重要目录

数据库目录
         /var/lib/mysql/
配置文件
         /usr/share /mysql(mysql.server命令及配置文件)
相关命令
         /usr/bin(mysqladmin mysqldump等命令)
启动脚本
         /etc/rc.d/init.d/(启动脚本文件mysql的目录)

Windows下使用Navicat for MySql连接



你可能遇到防火墙原因而出现以下错误:

请参考:连接MySQL错误:Can't connect to MySQL server (10060)


错误:1130 host is not allowed to connect to this mysql server

解决方法:

1。 改表法。

可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

mysql -u root -pvmwaremysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

2. 授权法。

例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH   PRIVILEGES;

这个测试通过,不过记得修改语句中的“myuser”和“mypassword”,我就是拿过来直接就执行了,结果搞了半天才发现。

如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH   PRIVILEGES;

如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器的dk数据库,并使用mypassword作为密码

GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH   PRIVILEGES;

在安装mysql的机器上运行:

1、d:\mysql\bin\>mysql   -h   localhost   -u   root //这样应该可以进入MySQL服务器

2、mysql>GRANT   ALL   PRIVILEGES   ON   *.*   TO   'root'@'%'   WITH   GRANT   OPTION //赋予任何主机访问数据的权限

3、mysql>FLUSH   PRIVILEGES //修改生效

4、mysql>EXIT //退出MySQL服务器

这样就可以在其它任何的主机上以root身份登录啦!

已标记关键词 清除标记
相关推荐
[root@bogon ~]# service mysql start Redirecting to /bin/systemctl start mysql.service [root@bogon ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.45 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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. mysql> grant all privileges on *.* to root@"%" identified by "new_mysql"; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to root@"bogon" identified by "new_mysql"; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@bogon ~]# iptables -F [root@bogon ~]# systemctl stop firewalld [root@bogon ~]# systemctl disable firewalld [root@bogon ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.131.131 netmask 255.255.255.0 broadcast 192.168.131.255 inet6 fe80::20c:29ff:fe4e:4a5b prefixlen 64 scopeid 0x20<link> ether 00:0c:29:4e:4a:5b txqueuelen 1000 (Ethernet) RX packets 284 bytes 28044 (27.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 395 bytes 31836 (31.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:d0:d8:4b txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@bogon ~]# ping www.baidu.com PING www.a.shifen.com (163.177.151.109) 56(84) bytes of data. 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=1 ttl=128 time=38.4 ms 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=2 ttl=128 time=34.7 ms 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=3 ttl=128 time=33.1 ms ^A64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=4 ttl=128 time=33.2 ms 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=5 ttl=128 time=30.1 ms 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=6 ttl=128 time=32.9 ms 64 bytes from 163.177.151.109 (163.177.151.109): icmp_seq=7 ttl=128 time=47.0 ms http://img.mukewang.com/climg/5d3d2999000169bb05660668.jpg 虚拟机网络是通的 Navicat的ip地址也没错 root的密码也没错 为什么就是连接不上呢?
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页