当前位置: 移动技术网 > IT编程>开发语言>PHP > 服务器远程连接mysql问题解决

服务器远程连接mysql问题解决

2019年02月22日  | 移动技术网IT编程  | 我要评论

一、 centos下解决远程连接不上的问题。
1、查看centos 下防火墙是否关闭:
通过进程: ps -aux |grep firewalld
ps -ef |grep firewalld
通过服务:pgrep firewalld
systemctl status firewalld
关闭防火墙: systemctl stop firewalld
service iptables off
2、远程连接走的是sshd 服务,是ssh协议,端口号是 22.
查看 sshd 服务是否已开启:
通过进程: ps -aux |grep sshd
通过服务:pgrep sshd
开启服务: systemctl start sshd
把sshd 服务加入到开机启动:chkconfig sshd on

3、查看ip地址。
ifconfig
在windows下,cmd窗口里面,ping一下上面的ip地址,看是否可以ping通。

二、数据库操作:

1、开启mysql。
systemctl start mariadb
2、首先是设置密码,会提示先输入密码
mysql_secure_installation
3、创建普通用户:
create user root@localhost identified by '123456';
mysql -u root -p
update user set host='%' where host='127.0.0.1';
flush privileges;
4、授权root用户远程登录:
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;

三、mysql远程连接不上的解决方法:
1、防火墙:
设置防火墙,开机不启动:
chkconfig firewalld off
关闭防火墙:
systemctl disable firewalld
systemctl stop firewalld
或者杀死 防火墙的进程。
查看防火墙的进程存在么:pgrep firewalld,
然后 杀死进程: kill pid
或者 pkill firewalld
2、没有远程权限
授予远程登录权限
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;

3、开启sshd服务: systemctl start sshd
把sshd 服务加入到开机启动:chkconfig sshd on

四、在windows 访问linux下的项目
开启linux中 apache服务,即httpd服务
systemctl start httpd
或者: service httpd start
windows下面浏览器访问linux下的项目:
浏览器地址栏输入ip地址即可:
(可通过ifconfig 查看自己的ip地址)
例如 192.168.0.1

五、windows下配置虚拟域名方法:
配置本地hosts 文件。
位置:c:\windows\system32\drivers\etc\hosts
添加 对应虚拟主机名即可。
192.168.226.129 linux.cc


mysql的crud;
添加:
insert into `user` (`id`, `username`, `passwd`, `sex`) values ('1', 'zhangsan', '12345', '')
更新:
update `user` set `sex`='女' where (`id`='2')
删除:
delete from `user` where (`id`='2')
查询:
select * from `user`;

一、 centos下解决远程连接不上的问题。
1、查看centos 下防火墙是否关闭:
通过进程: ps -aux |grep firewalld
ps -ef |grep firewalld
通过服务:pgrep firewalld
systemctl status firewalld
关闭防火墙: systemctl stop firewalld
service iptables off
2、远程连接走的是sshd 服务,是ssh协议,端口号是 22.
查看 sshd 服务是否已开启:
通过进程: ps -aux |grep sshd
通过服务:pgrep sshd
开启服务: systemctl start sshd
把sshd 服务加入到开机启动:chkconfig sshd on

3、查看ip地址。
  ifconfig
  在windows下,cmd窗口里面,ping一下上面的ip地址,看是否可以ping通。


报错 怎么办?

数据库连接不上?出现下面的问题?
  can't connect to local mysql server through socket '/var/lib/mysql/mysql.sock ???
  怎么办?
  先查看 /etc/rc.d/init.d/mysqld status 看看mysql是否已经启动.
  如果是权限问题,则先改变权限 #chown -r mysql:mysql /var/lib/mysql

  [root@localhost ~]# /etc/init.d/mysqld start
  启动 mysql: [ 确定 ]
  [root@localhost ~]# mysql -uroot -p

  10038?(远程没有授权)
  10060?(加入安全组)


二、数据库操作:
1、开启mysql。
  systemctl start mariadb
  2、首先是设置密码,会提示先输入密码
  mysql_secure_installation
3、创建普通用户:
  create user zhangsan@localhost identified by 'root';
  mysql -u root -p
  update user set host='%' where host='127.0.0.1';
  flush privileges;
  4、授权root用户远程登录:
  grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
  flush privileges;
  update user set user='root' where host='localhost';
三、mysql远程连接不上的解决方法:
1、防火墙:
  设置防火墙,开机不启动:
  chkconfig firewalld off
关闭防火墙:
  systemctl disable firewalld
  systemctl stop firewalld
  或者杀死 防火墙的进程。
  查看防火墙的进程存在么:pgrep firewalld,
  然后 杀死进程: kill pid
  或者 pkill firewalld
2、没有远程权限
  授予远程登录权限
  grant all privileges on *.* to 'root'@'%' identified by '123456';
  flush privileges;

  3、开启sshd服务: systemctl start sshd
  把sshd 服务加入到开机启动:chkconfig sshd on

四、在windows 访问linux下的项目
  开启linux中 apache服务,即httpd服务systemctl start httpd或者: service httpd start
  windows下面浏览器访问linux下的项目:浏览器地址栏输入ip地址即可:(可通过ifconfig 查看自己的ip地址)例如 192.168.0.1

五、windows下配置虚拟域名方法:
  配置本地hosts 文件。
  位置:c:\windows\system32\drivers\etc\hosts
  添加 对应虚拟主机名即可。
  192.168.226.129 linux.cc


mysql的crud;
添加:
  insert into `user` (`id`, `username`, `passwd`, `sex`) values ('1', 'zhangsan', '12345', '')
更新:
  update `user` set `sex`='女' where (`id`='2')
删除:
  delete from `user` where (`id`='2')
查询:
  select * from `user`;

六、虚拟主机
  <virtualhost *:80>
  serveradmin webmaster@dummy-host.example.com
  documentroot /www/docs/dummy-host.example.com
  servername dummy-host.example.com
  errorlog logs/dummy-host.example.com-error_log
  customlog logs/dummy-host.example.com-access_log common
  </virtualhost>

七、设置开机启动:默认图形化界面切换为 命令行模式
   修改为命令模式multi-user.target:
  [root@localhost ~]# systemctl set-default multi-user.target
  rm '/etc/systemd/system/default.target'
  ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'
  [root@localhost ~]# systemctl get-default
  得到:multi-user.target:达到效果。
  在切换为:图形化模式:systemctl set-default graphical.target

八、配置文件说明
  a: httpd.conf apache的主配置文件。
  b: php.ini php的主配置文件
  d: httpd-vhost.conf 配置虚拟主机的时候,更改的文件
  e:my.cnf linux下mysql的主配置文件

注意: windows下面mysql的主配置文件 my.ini

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网