日期:2014-05-16  浏览次数:20878 次

Ubuntu10下Mysql-5.1.56安装
经过前期一系列的Ubuntu10下开发软件的安装,现在把最后的数据库mysql5.1装好了。基本上搭建基于Java Web应用的LNMJ or LAMJ架构的环境已经搭建完毕。接下来打算写一下L(linux)N(nginx)M(mysql)J(java web tomcat)架构的负载均衡与集中式Memcached集群的文章。有喜欢的,可以先行安装环境。

创建mysql用户和组
sudo groupadd mysql
sudo useradd -r -g mysql mysql

Note:
-r option to create a user that does not have login permissions to your server host. Omit this option to permit logins for the user。
-g:指定用户所属的群组。

解压和移动到应用目录
tar –zxvf mysql-5.1.56-linux-i686-glibc23.tar.gz
sudo mv mysql-5.1.56-linux-i686-glibc23 /usr/local/mysql51


建立软连接
为mysql51目录建立软连接mysql,以便快速访问mysql51目录。

//相当于cd /usr/local/mysql51 和cd /usr/local/mysql等效
sudo ln -s  /usr/local/mysql51 mysql
cd /usr/local/mysql


访问权限配置
cd /usr/local/mysql
//注意后面有小数点
sudo chown -R mysql .
//将组属性改为mysql组。
sudo chgrp -R mysql .


There are four symbolic link files whose ownership is not changed(/usr/mysql/lib).
lrwxrwxrwx 1 7155 staff 24 Mar 9 06:28 libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
lrwxrwxrwx 1 7155 staff 24 Mar 9 06:28 libmysqlclient.so -> libmysqlclient.so.16.0.0
lrwxrwxrwx 1 7155 staff 26 Mar 9 06:28 libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
lrwxrwxrwx 1 7155 staff 26 Mar 9 06:28 libmysqlclient_r.so -> libmysqlclient_r.so.16.0.0
//为了更改以上几个文件的权限,需要执行下面的命令。
guangbo@guangbo-laptop:/usr/local/mysql/lib$ sudo chown -h mysql:mysql libmysqlclient.so.16 libmysqlclient.so libmysqlclient_r.so.16 libmysqlclient_r.so


创建MySQL授权表初始化
sudo scripts/mysql_install_db --user=mysql 

//将文件的所有属性改为root用户。
sudo chown -R root .
//将数据目录的所有属性改为mysql用户。
sudo chown -R mysql data
//下面这条给所有人弄data的权限,仅为了方便调试,不需要
sudo chmod a+rwx -R data

//下面的命令可选。copy配置文件到相关目录
sudo cp support-files/my-medium.cnf /etc/my.cnf
启动mysql
sudo bin/mysqld_safe --user=mysql &
//下面的命令可选。开机自启动mysql.server服务.
//To start mysqld at boot time you have to copy
//support-files/mysql.server to the right place for your system
sudo cp support-files/mysql.server /etc/init.d/mysql.server
service mysql.server start
//查看启动是否正常
./bin/mysqladmin version
./bin/mysqladmin  Ver 8.42 Distrib 5.1.56, for pc-linux-gnu on i686
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version 5.1.56-log
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 12 min 41 sec

修改mysql密码
guangbo@guangbo-laptop:/usr/local/mysql$ ./bin/mysqladmin -u root -p password ='root'


授权GRANT充许各ip访问
当重置密码后,还是无法访问,如通过ip,另外的机器等,请用受权,权限自行配置

//不能通过localhost和127.0.0.1。只能是服务器名。
mysql -h guangbo-laptop -u root –p
//添加新ip
mysql>INSERT INTO user (Host,User,Password) VALUES('192.168.1.2','root',PASSWORD('root'));
mysql>FLUSH PRIVILEGES;
//给某ip授权
mysql>GRANT ALL ON *.* TO root@'192.168.1.2' IDENTIFIED BY 'root' WITH GRANT OPTION;
//root用户可以在所有ip访问
mysql>GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'root' WITH GRANT OPTION