ubuntu10.04安装mysql[有很多借鉴他人的地方]

来源:互联网 发布:java正则表达式单引号 编辑:程序博客网 时间:2024/04/30 19:57

历尽艰辛。勉强安装完成。不知道能不能用。
mysql版本:mysql-5.1.48-linux-i686-glibc23.tar.gz
ubuntu版本:10.04

解压 
root@xlu-desktop:/home/xlu# tar -zvxf mysql-5.1.48-linux-i686-glibc23.tar.gz
root@xlu-desktop:/home/xlu# cd mysql-5.1.48-linux-i686-glibc23
   [root@localhost mysql-5.1.30-linux-i686-glibc23]# ls
     bin      docs   INSTALL-BINARY  mysql-test  share
COPYING  EXCEPTIONS-CLIENT  lib             README      sql-bench
data     include            man             scripts     support-files

可以看到,加压后的目录中并没有configure目录。所以如果你运行./configure的话,会出现找不到文件的错误。先将解压后的目录mv到/usr/local下并用名为mysql的目录存储(此处重点)

root@xlu-desktop:/home/xlu# mv mysql-5.1.48-linux-i686-glibc23 /usr/local/mysql

很重要的一步,是创建一个用户组,并在改组下创建一个用户。这里我们创建一个mysql组,并创建一个mysql用户。

root@xlu-desktop:/home/xlu# groupadd mysql
root@xlu-desktop:/home/xlu# useradd -g mysql mysql

下面添加mysql的配置文件,改文件的模板在mysql/support-files下,共有5个cnf配置文件,先看一下:
root@xlu-desktop:/usr/local/mysql# cd support-files/
root@xlu-desktop:/usr/local/mysql/support-files# ls
binary-configure   my-huge.cnf             mysqld_multi.server
config.huge.ini    my-innodb-heavy-4G.cnf  mysql-log-rotate
config.medium.ini  my-large.cnf            mysql.server
config.small.ini   my-medium.cnf           ndb-config-2-node.ini
magic              my-small.cnf

改文件分别适应于不同的安装配置,具体说明如下。
  
my-small.cnf 最小配置安装,内存<=64M,数据数量最少 
my-large.cnf               内存=512M 
my-medium.cnf             32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存  
my-huge.cnf               1G<内存<2G,服务器主要运行mysql 
my-innodb-heavy-4G.cnf    最大配置安装,内存至少4G 
 
 根据情况,暂时选择my-medium.cnf进行配置。

root@xlu-desktop:/usr/local/mysql# cp support-files/my-medium.cnf /etc/my.cnf

下面进行访问权限配置,用mysql_install_db创建MySQL授权表初始化,并设置mysql,root帐号访问权限

root@xlu-desktop:/usr/local/mysql# chown -R mysql .  (mysql后面还有个点。不写会报错)
root@xlu-desktop:/usr/local/mysql# chgrp -R mysql .
root@xlu-desktop:/usr/local/mysql# scripts/mysql_install_db --user=mysql(注意user前面是两个'-')
Installing MySQL system tables...
110227 16:17:30 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
110227 16:17:32 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h xlu-desktop password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

root@xlu-desktop:/usr/local/mysql# chown -R root .   (这里也有个点不要忘了!!)
root@xlu-desktop:/usr/local/mysql# chown -R mysql data

下面启动mysql
root@xlu-desktop:/usr/local/mysql# bin/mysqld_safe --user=mysql & (user前面有两个'-'!!)
[1] 3141
root@xlu-desktop:/usr/local/mysql# 110227 16:26:48 mysqld_safe Logging to '/usr/local/mysql/data/xlu-desktop.err'.
110227 16:26:48 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

启动mysql,并给root用户设置初始密码
root@xlu-desktop:/usr/local/mysql# bin/mysqladmin -u root password 123
root@xlu-desktop:/usr/local/mysql# bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 2
Server version: 5.1.48-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
(退出的方法在帮助里面找。其实就是'/q'。^^)
mysql> /q
Bye

这样mysql的安装就完成了。

下面,我们还要配置一下,以便mysql能够开机自启动。
root@xlu-desktop:/usr/local/mysql# cp support-files/mysql.server /etc/init.d/mysqld

这一句的作用是将 mysql加入开机启动服务。进入linux后就自动开启mysql

这样就能用service mysqld start 等命令了。解决了mysqld: unrecognized service的问题
root@xlu-desktop:/usr/local/mysql# chmod 700 /etc/init.d/mysqld
root@xlu-desktop:/usr/local/mysql# chkconfig --add mysqld
这个命令的 作用是把mysql添加为系统服务,服务名为mysqld

 

问题一:

The program 'mysql' can be found in the following packages:

 * mysql-client-core-5.1

 * mysql-client-5.0

 * mysql-cluster-client-5.1

Try: apt-get install <selected package>

这是不识别mysql命令。

 

解决方法:mysql命令路径为/usr/local/mysql/bin/
在/usr/local/mysql/bin/的路径下输入
export PATH=$PATH:/usr/local/mysql/bin

然declare -x PWD="/usr/local/mysql/bin"
后输入export检查是否成功。

declare -x PWD="/usr/local/mysql/bin" 有这句就对了。

这是给mysql加入一个永久的系统环境变量,这样在打开终端后,无论处于哪一个目录都可以直接mysql -uxxx -p了

 

主要的参考是
http://exceljava.javaeye.com/blog/367197(这个里面mysql和启动的时候user前面都少了一个'-'。其他都正确,配置相关也可以参考网站后面写的。有些错误的解法)

http://www.myhack58.com/Article/sort099/sort0102/2011/29399.htm(这个网站后面mysql的配置很重要。但是因为系统不是ubuntu所以有些文件路径不一样。那个/etc/init.d/的路径就是直接用的

 

有什么问题看

http://hi.baidu.com/puma525/blog/item/d572efcde19bf5450fb345cb.html

问题超全