恒晖瑶 发表于 2018-10-8 09:05:16

mysql的安装,关于/etc/init.d/下没有mysqld的命令,及php与mysql的连接测试

  yum install php php-mysql mysql
  yum install mysql-server //这个必须安装,才会有/etc/init.d的mysqld
  mysql 使用的端口为3306
  注意1.我们验证php程序执行环境
  方法,在DoucumentRoot路径下建个test.php文件
  
  用浏览器浏览后有php的页面显示。
  2.测试php程序与mysql通信
  方法,在 test.php文件中修改
  
  若出现报错:SQLSTATE Can't connect to MySQL server on 'XXX' (13)
  这是SELinux不允许访问外网,
  简单点就可以使用setenfroce=0;就可以了。
  或者: 使用命令getsebool - get SELinux boolean value(s)
  命令 getsebool -a | grep httpd   
  allow_httpd_anon_write --> off
  allow_httpd_mod_auth_ntlm_winbind --> off
  allow_httpd_mod_auth_pam --> off
  allow_httpd_sys_script_anon_write --> off
  httpd_builtin_scripting --> on
  httpd_can_check_spam --> off
  httpd_can_network_connect --> off
  httpd_can_network_connect_cobbler --> off
  httpd_can_network_connect_db --> off
  httpd_can_network_memcache --> off
  httpd_can_network_relay --> off
  httpd_can_sendmail --> off
  httpd_dbus_avahi --> on
  httpd_dbus_sssd --> off
  httpd_enable_cgi --> on
  httpd_enable_ftp_server --> off
  httpd_enable_homedirs --> off
  httpd_execmem --> off
  httpd_manage_ipa --> off
  httpd_read_user_content --> off
  httpd_run_preupgrade --> off
  httpd_run_stickshift --> off
  httpd_serve_cobbler_files --> off
  httpd_setrlimit --> off
  httpd_ssi_exec --> off
  httpd_tmp_exec --> off
  httpd_tty_comm --> on
  httpd_unified --> on
  httpd_use_cifs --> off
  httpd_use_fusefs --> off
  httpd_use_gpg --> off
  httpd_use_nfs --> off
  httpd_use_openstack --> off
  httpd_verify_dns --> off
  注意这里httpd_can_network_connect --> off
  这里设置使用命令setsebool httpd_can_network_connect 1
  PS: 1. 若出现错误Lost connection to MySQL server at 'reading initial communication packet', system error: 111
  有可能是mysql服务没打开,可用命令service mysqld start
  2.若出现错误ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.18.9' (113)
  很可能是防火墙的问题
  iptables -F
  iptables -L
  这样就解决了

页: [1]
查看完整版本: mysql的安装,关于/etc/init.d/下没有mysqld的命令,及php与mysql的连接测试