Chinaunix首页 | 论坛 | 博客
  • 博客访问: 609269
  • 博文数量: 244
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-27 09:53
个人简介

记录学习,记录成长

文章分类

全部博文(244)

我的朋友

分类: LINUX

2015-06-04 19:05:54


一、安装 MySQL

首先来进行 MySQL 的安装。打开超级终端,输入:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# yum install mysql mysql-server  

安装完毕,让 MySQL 能够随系统自动启动:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# chkconfig --levels 235 mysqld on  
  2. [root@localhost ~]# /etc/init.d/mysqld start  

设置 MySQL 数据 root 账户的密码:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# mysql_secure_installation  

当出现如下提示时候直接按回车:

Sh_javascript sh_sourcecode代码  收藏代码
  1. Enter current password for root  

备注:我的没有出现上述情况,而是
直接输入回车会出现(可能我之前有误操作吧)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
我输入了none
[root@iZ28dr3wqtiZ mysql]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
我是没有先管这些,而是先继续向后做,后面的做的没问题了,又回来解决这个问题,没遇到这个问题就好,遇到了先扔这,配好了再回来解决:大致方法如下:
1.错误描述: Mysql中添加用户之后可能出现登录时提示ERROR 1045 (28000): Access denied for user的错误. 
原因分析: 在mysql.user表中可能出现user为空的记录,
mysql> select host,user from user; 
+------------------+------+ 
| host | user | 
+------------------+------+ 
| % | test | 
| localhost | | 
| localhost | root | 
+------------------+------+ 
3 rows in set (0.00 sec) 
解决 办法: 删除这些为空的用户或者更新为其他用户名 
删除user.user中值为NULL的,或更新NULL为test 
1)delete from user where user is NULL 
2)update user set user='test' where user is NULL 
意外的情况: 如果上述方法没有效果,依然出现空用户,则可以利用图形化用户client删除.(我没试过)

2.对于MYSQL ERROR 1045 (28000): Access denied for user (using password: YES),这个拒绝访问问题
解决问题思路: 
第一步,先停了mysql服务,/etc/rc.d/init.d/mysqld stop,然后使用跳过受权表访问,命令如下:mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  
第二步,mysql -uroot mysql 登录mysql
第三步,访问mysql数据库下的user表。在我的机器上输入mysql>  select * from user;(不要忘了分号) 得到的,竟然是 
Empty set (0.00 sec)。这说明了,我的mysql没有任何可以访问的用户。这就是问题所在 
第四步,

INSERT INTO user
(host,user,password,select_priv,insert_priv,update_priv,delete_priv,ssl_cipher)
VALUES('localhost','admin(自己设定的登录名)',password('admin(登录名的密码)'),'Y','Y','Y','Y','');
Query OK, 1 row affected, 3 warnings (0.00 sec) 
返回成功,没问题了。
输入:mysql> FLUSH PRIVILEGES;   
        mysql> quit 
第五步,测试,再重启下mysql服务,重新登录 
# /etc/init.d/mysqld  restart 

# mysql -u admin -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> 
测试成功!
提示:mysql系统中的mysql数据库,存储的是系统数据,像这里的user表存储的是用户信息及其访问权限,还有其他,例如你要新建一个数据库mydb,这数据库有用户me管理的话,mysql数据库里面的db表就会存储相关信息。
好的,问题解决了!没出现问题的请无始上面哪一些,下面是刚才的继续》》》》》》》》

出现如下再次回车:


Sh_javascript sh_sourcecode代码  收藏代码
  1. Set root password? [Y/n]  

出现如下提示输入你需要设置的密码,回车后在输入一次确认:

Sh_javascript sh_sourcecode代码  收藏代码
  1. New password:  

接下来还会有四个确认,分别是:

Sh_javascript sh_sourcecode代码  收藏代码
  1. Remove anonymous users? [Y/n]  
  2. Disallow root login remotely? [Y/n]  
  3. Remove test database and access to it? [Y/n]  
  4. Reload privilege tables now? [Y/n]  

直接回车即可。

二、安装 Apache 组件

  由于 CentOS 已经封装了 Apache,直接运行安装:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# yum install httpd  

同样配置系统让 Apache 随系统启动:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# chkconfig --levels 235 httpd on  

配置完毕,启动 Apache:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# /etc/init.d/httpd start  

  此时已经可以访问你的服务器,不出意外的话,能够看到 “Apache 2 Test Page powered by CentOS” 的测试页面。注意,如果其他机器访问这台服务无法显示这个页面,而直接在这台服务器上可以访问的话,一般情况下是 CentOS 自带的防火墙禁止了。你只需要进入防火墙,将 “WWW” 对应的 “80” 端口打开即可。

  注意:在 CentOS 中 Apache 的默认根目录是 /var/www/html,配置文件 /etc/httpd/conf/httpd.conf。其他配置存储在 /etc/httpd/conf.d/ 目录。

三、安装 PHP

输入如下指令安装 PHP:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# yum install php  

需要重新启动 Apache 服务:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# /etc/init.d/httpd restart  

四、测试 PHP 相关信息

  这步实际上可以省略,但是为了测试是否安装成功,你可以新建一个 PHP 页面进行测试,使用 vim 编辑器新建:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# vi /var/www/html/info.php  

按 “i” 键进行编辑,输入:

Sh_javascript sh_sourcecode代码  收藏代码
  1. phpinfo();  
  2. ?>  

编辑完毕,按 “ESC” 键退出编辑模式,接着输入:

Sh_javascript sh_sourcecode代码  收藏代码
  1. :wq  

然后回车,即保存并退出。

  此时你可以访问你的站点地址,例如 “”,查看是否能看到相关的 PHP 信息。

  看到这样的图,就说明 PHP 安装成功了。

五、将 PHP 模块和 MySQL 模块关联起来

  还需要将 PHP 和 MySQL 关联起来,才能正常工作。搜索模块:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# yum search php  

安装相关模块:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc  

需要重启 Apache 模块才能生效:

Sh_javascript sh_sourcecode代码  收藏代码
  1. [root@localhost ~]# /etc/init.d/httpd restart  

  再次刷新刚才建立的 “info.php” 页面,往下拉找到相关 MySQL 模块,看是否检测到相关信息。

如果看到如上图相关信息,则说明 MySQL 工作正常了。










参考文章:
                http://focus-zhong.iteye.com/blog/1888304

阅读(1294) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~