正确安装mysql

2014-08-25 开源中国
二、安装mysql

shell> groupadd mysql                #创建mysql的用户组和用户
shell> useradd -g mysql mysql
shell> cd /server/software/
shell> cp mysql-5.1.22-rc-linux-i686-glibc23.tar.gz /usr/local/
shell> cd /usr/local/
shell> tar -zxvf mysql-5.1.22-rc-linux-i686-glibc23.tar.gz
shell> ln -s mysql-5.1.22-rc-linux-i686-glibc23 mysql
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql     #初始化安装mysql数据库
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
shell> cp support-files/mysql.server /etc/init.d/mysql    #设置mysql开机自启动
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> /etc/init.d/mysql start
如果这一步骤tar -zxvf mysql-5.1.22-rc-linux-i686-glibc23.tar.gz 失败,可能是下载的包有误,换个mirror重新下载mysql版本安装
如果start过程失败:Starting MySQL.Manager of pid-file quit without updating fi[失败],则执行下面的命令:
shell> rm -rf /var/lib/mysql
然后重新执行下面步骤:
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
shell> cp support-files/mysql.server /etc/init.d/mysql
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> /etc/init.d/mysql start                            #启动mysql
设置mysql密码为123456:
shell> /usr/local/mysql/bin/mysqladmin -u root password 'shengzhan'
设置mysql开机自启动:
shell> vi /etc/rc.d/rc.local
添加下面内容:
/usr/local/mysql/bin/mysqld_safe --user=mysql&
登陆mysql:
shell> /usr/local/mysql/bin/mysql -uroot -p123456

权限分配:
grant all privileges on *.* to username@172.18.26.19 identified by 'password' with grant option

grant all privileges on *.* to 'root'@'%'  identified by 'shengzhan' with grant option;

mysql5远程连接服务器时,出现类似:
ERROR 1044: Access denied for user: '@127.0.0.1' to database 'mysql'
的错误。
说明你没有将权限下放到远端连接帐户上,由于mysql的安全性在不断的提高,权限设置默认是拒绝的,你必须自己开放权限。
在服务器上用mysql -h 192.168.0.1 -u root -p mysql命令登录mysql数据库
然后用grant命令下放权限。
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'root-password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO root@127.0.0.1 IDENTIFIED BY 'root-password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'root-password' WITH GRANT OPTION;
例如:
  GRANT   ALL   PRIVILEGES   ON   *.*   TO   root@'%'nbsp;nbsp; identifiednbsp;nbsp; bynbsp;nbsp; '123456'nbsp;nbsp;
注意:自己根据情况修改以上命令中的 “用户”“ip地址”“密码”。

GBK编码:

用packages安装的mysql5.1,不支持GBK编码,只支持UTF8编码。具体表现:
  在打开一个用GBK编码的数据库时,提示
    ERROR 1273 (HY000): Unknown collation 'gbk_chinese_ci' in table 'data_plus' definition
    set names gbk; 和 SET character_set_client = gbk;提示:
ERROR 1115 (42000): Unknown character set: 'gbk'
  最后没办法,只好用ports重新编译。
   cd /usr/ports/databases/mysql51-server
   make WITH_CHARSET=gbk WITH_XCHARSET=all WITH_COLLATION=gbk_chinese_ci BUILD_STATIC=yes install clean
   (其实,在make install clean 时,就有个参数提示,把前三个设置好就可以了。)
查看支持的编码:
   SHOW VARIABLES LIKE 'character_set_%';
   SHOW VARIABLES LIKE 'collation_%';




一、安装apache2.2.9
shell> tar -zxvf httpd-2.2.9.tar.gz
shell> cd httpd-2.2.9
shell> ./configure --prefix=/usr/local/apache2  
          --enable-modules=most
          --enable-modules=so
          --enable-rewrite
shell> make
shell> make install
注明:
a、./configure --prefix=/usr/local/apache2 安装路径
b、--enable-modules=most 安装常用模块
apache的httpd.conf配置:
shell> vi /usr/local/apache/conf/httpd.conf
apache默认最大并发进程: ServerLimit=256,并发进程:MaxClients=150
修改并ServerLimit=2000 MaxClients =1000
修改ServerName www.example.com:80在其下设置 ServerName 为你网站名,也可用IP代替
修改DocumentRoot,设置 WEB 服务器的根目录
修改DirectoryIndex,添加index.php
保存退出。重启apache:
shell> /usr/local/apache/bin/apachectl start
设置为开机自启动方法:
shell> vi /etc/rc.d/rc.local
添加下面内容:
/usr/local/apche/bin/apchect1 -k start