服務器遠程連接mysql問題解決


一、 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM