`
lucane
  • 浏览: 119098 次
  • 性别: Icon_minigender_1
  • 来自: 江湖
社区版块
存档分类
最新评论

Ubuntu二进制安装MySQL 5.5

阅读更多
下载地址
引用
http://mysql.oss.eznetsols.org/Downloads/MySQL-5.5/mysql-5.5.8-linux2.6-i686.tar.gz

下载完按照INSTALL-BINARY装了遍出错。

执行到
scripts/mysql_install_db

出现
FATAL ERROR: Could not find mysqld
The following directories were searched:
    /usr/libexec
    /usr/sbin
    /usr/bin
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

按着网上的
引用
http://scnjl.iteye.com/blog/655432

引用
安装或者重新mysql-5.1.30时mysql_install_db出现FATAL ERROR: Could not find mysqld错误解决,
因为/etc/mysql/下出现了个my.cnf
解决方法:
mv  /etc/mysql/my.cnf   /etc/mysql/my.cnf.bak
cp  support-files/my-medium.cnf   /etc/cnf


改了再执行
Installing MySQL system tables...
110108 16:03:03 [Warning] Can't create test file /home/guohai/dev/a/mysql/mysql-5.5.8-linux2.6-i686/data/KNIGHT.lower-test
110108 16:03:03 [Warning] Can't create test file /home/guohai/dev/a/mysql/mysql-5.5.8-linux2.6-i686/data/KNIGHT.lower-test
ERROR: 1005  Can't create table 'db' (errno: 13)
110108 16:03:03 [ERROR] Aborting
110108 16:03:03 [Note] ./bin/mysqld: Shutdown complete
Installation of system tables failed!  Examine the logs in
./data for more information.
You can try to start the mysqld daemon with:
    shell> ./bin/mysqld --skip-grant &
and use the command line tool ./bin/mysql
to connect to the mysql database and look at the grant tables:
    shell> ./bin/mysql -u root mysql
    mysql> show tables
Try 'mysqld --help' if you have problems with paths.  Using --log
gives you a log in ./data that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS.  Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us!  And remember, if
you do mail us, you MUST use the ./bin/mysqlbug script!


晕菜了,错误这么多,放弃上面的
严格按照官方网站的安装方法来一次,网站上的安装手册里面比较全
删掉/etc/mysql文件夹,还有刚刚拷贝到/etc下的cnf文件,确保系统当中没有MySQL相关的配置文件

引用
http://dev.mysql.com/doc/refman/5.5/en/binary-installation.html
http://dev.mysql.com/doc/refman/5.5/en/postinstallation.html
http://dev.mysql.com/doc/refman/5.5/en/unix-postinstallation.html


创建用户和组
创建链接
授权own和grp给mysql-5.5.8-linux2.6-i686文件夹,就是下面的BASE_DIR

执行的mysql_install_db的时候后面带参数
shell> scripts/mysql_install_db --user=mysql \
         --basedir=BASE_DIR \
         --datadir=BASE_DIR/data

其中BASE_DIR就是你解压出来的文件放的地方,datadir就是你想让数据文件存放的地方

执行完成,我的出现下面的结果
lucane@KNIGHT:/usr/local/mysql$ sudo scripts/mysql_install_db --user=mysql --basedir=~/dev/a/mysql/mysql-5.5.8-linux2.6-i686 --datadir=~/dev/a/mysql/mysql-5.5.8-linux2.6-i686/data

Installing MySQL system tables...
OK
Filling help tables...
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:

~/dev/a/mysql/mysql-5.5.8-linux2.6-i686/bin/mysqladmin -u root password 'new-password'
~/dev/a/mysql/mysql-5.5.8-linux2.6-i686/bin/mysqladmin -u root -h MACHINE_NAME password 'new-password'

Alternatively you can run:
~/dev/a/mysql/mysql-5.5.8-linux2.6-i686/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 ~/dev/a/mysql/mysql-5.5.8-linux2.6-i686 ; ~/dev/a/mysql/mysql-5.5.8-linux2.6-i686/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ~/dev/a/mysql/mysql-5.5.8-linux2.6-i686/mysql-test ; perl mysql-test-run.pl

Please report any problems with the ~/dev/a/mysql/mysql-5.5.8-linux2.6-i686/scripts/mysqlbug script!

总之上面的意思就是安装系统表成功
想要在开机启动MySQL该怎么办(相反我喜欢用到的时候开启,所以这步省略)

设置root密码,先开启MySQL,然后执行mysqladmin设置密码
带-h参数的主要用来远程访问的

或者可以通过mysql_secure_installation来完成,这是推荐的方法

开启数据库用这个bin/mysqld_safe &

最后可以测试MySQL

实际上启动数据库是在前面,官方的提示把设置相关参数放前面解释我觉得并不好
那我们现在关键的就是要启动数据库了,我用的是bin/mysqld_safe --user=mysql &
注意带--user参数的意义,参见
引用
http://dev.mysql.com/doc/refman/5.5/en/unix-postinstallation.html

引用
It is important that the MySQL server be run using an unprivileged (non-root) login account. To ensure this if you run mysqld_safe as root, include the --user option as shown. Otherwise, you should execute the script while logged in as mysql, in which case you can omit the --user option from the command.
For further instructions for running MySQL as an unprivileged user, see Section 5.3.6, “How to Run MySQL as a Normal User”.

就是说你可以以普通用户来启动MySQL,如果你当前登录操作系统的是root用户,那么你就可以带--user参数来以普通身份启动,如果你就是以mysql用户登录操作系统的,那你这个参数就可以省略
所以不管这样,这个--user参数都可以带上
&符号是后台启动
可以参看下
引用
How to Run MySQL as a Normal User(http://dev.mysql.com/doc/refman/5.5/en/changing-mysql-user.html)

lucane@KNIGHT:/usr/local/mysql$ bin/mysqld_safe --user=mysql &

[1] 17982
lucane@KNIGHT:/usr/local/mysql$ 110108 22:36:47 mysqld_safe Logging to '/usr/local/mysql/data/KNIGHT.err'.
110108 22:36:47 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

bin/mysqld_safe: 739: cannot create /usr/local/mysql/data/KNIGHT.err: Permission denied
eval: 1: cannot create /usr/local/mysql/data/KNIGHT.err: Permission denied

110108 22:36:47 mysqld_safe mysqld from pid file /usr/local/mysql/data/KNIGHT.pid ended
bin/mysqld_safe: 783: cannot create /usr/local/mysql/data/KNIGHT.err: Permission denied

他说不能记日志,拒绝了,这应该是因为我当前是lucane用户,不是root也不是mysql用户,data文件夹在之前我们已经授权给了mysql了,所以就出错了

这个时候我以sudo启动,即
lucane@KNIGHT:/usr/local/mysql$ sudo bin/mysqld_safe --user=mysql &

[1] 18781
出现了串数字,这就是MySQL服务的进程号

检测下是否真的开启
lucane@KNIGHT:/usr/local/mysql$ bin/mysqladmin version

bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

出错了,缺少文件

目前我的系统上没有my.cnf和mysql.sock
引用
http://dev.mysql.com/doc/refman/5.5/en/option-files.html

其中mysql.sock只是个本地化加速的东西,可以不要
但没有他的话不能用mysqladmin和mysql_secure_installation这些命令

网上一些帖子说要么这个文件是放在其他的地方了,通过引入链接就可以搞定,可是我的额机器里面根本就没有这个文件,后来才知道这个文件是动态生成的
引用
http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html
http://dev.mysql.com/doc/refman/5.5/en/problems-with-mysql-sock.html

但我们已经可以登录mysql
这个时候root密码是空的
lucane@KNIGHT:/usr/local/mysql$ bin/mysql -h 127.0.0.1 -P 3306 -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.8 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql.sock解决办法,把my.cnf拷贝到/etc/mysql/下,修改其中的内容,比如
mysqld下面的
引用
socket = /etc/mysql/mysql.sock

之后保存,然后再重启就会在/etc/mysql/生成mysql.sock
(最后我试了下,只有先sudo -i切换到root下面,再执行才有生成,而普通的sudo sudo mysqld_safe --user=mysql &并没有立即生成sock这个文件,有时候又不需要这么做,不是很懂,希望高手指点)

这样mysqladmin可以用了,还剩个mysql_secure_installation没有执行,实际这个内容就是我们在windows里面装完之后最后一步设置,像什么禁止root远程登录,禁止匿名账户,修改root密码等等
先不管这个了

先来装GUI客户端下载之后解压到某个位置,拷贝.desktop到桌面之后,还不能直接执行,会提示“未信任的应用程序启动器”
这时候只要右击,属性,权限,允许以程序执行文件,打钩就可以了
再次双击就可以执行了,第一次比较慢
安装方法参见:
引用
http://dev.mysql.com/doc/administrator/en/install-generic-tarball.html

图形化界面登录的时候,点击Details,填入Socket的位置,然后输入用户名等等就可以登录了

这样所有问题搞好之后就可以来修改root密码了
bin/mysql_secure_installation
结果还是报找不到mysql.sock它给的路径是在/tmp/下的,我路径已经改了,证明这个命令读取的配置文件参数没有生效,关闭terminal,再来。
结果还是不行
用文本编辑器打开mysql_secure_installation这个脚本文件
发现里面实际上还是去调用了mysql这个命令
那么为什么我们直接用命令可以访问,但是用这个脚本就不能访问呢?

可以看下脚本中有这么个方法
find_mysql_client()
{
  for n in ./bin/mysql mysql
  do  
    $n --no-defaults --help > /dev/null 2>&1
    status=$?
    if test $status -eq 0
    then
      mysql_client=$n
      return
    fi  
  done
  echo "Can't find a 'mysql' client in PATH or ./bin"
  exit 1
}

在执行所有的操作的时候都会调用do_query,都会调用find_mysql_client的结果

所以说我相信直接可以一步步把里面的SQL语句拿到SQL Browser里面去执行是一样的
但是目前没有这么做,还是要找原因

我在my.cnf中已经将client端的socket指向了如下路径,为什么他还要去搜索/tmp路径呢
引用
socket = /etc/mysql/mysql.sock

当然此刻比较简单的办法就是往/tmp文件夹下做个符号链接,但是还是要找原因
让他直接去搜索/etc下的不更好
于是看见find_mysql_client
带有这么一个东西 --no-defaults
这大概就是mysql的参数吧
果断man mysql
貌似没有找到,于是mysql --help,看到了这么段
引用
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit.
--no-defaults           Don't read default options from any option file.
--defaults-file=#       Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.

先是说mysql会按照一个顺序去搜索option file,下面的参数可以指定他不去搜索,或者只搜索某个文件等等,貌似还有这几个参数放在mysql的第一个参数位置上

mysql_secure_installation带--no-defaults的就是说Don't read default options from any option file.
不去读取任何配置文件,那么他当然读自己的默认参数咯,即/tmp下面,刚好/tmp下又没有这个文件,所以就报错了
那么我把--no-defaults参数改下应该就行了,改成--defaults-file=#
在我这里就是--defaults-file=/etc/mysql/mysql.sock
root@KNIGHT:~# mysql_secure_installation
Can't find a 'mysql' client in PATH or ./bin

又出错了
问题是找到了,可是怎么解决呢
shell脚本也不是很懂
看到
do_query() {
    echo "$1" >$command
    #sed 's,^,> ,' < $command  # Debugging
    $mysql_client --defaults-file=$config <$command
    return $?
}

于是想可不可以在mysql_secure_installation后面给他加个参数呢,让他去改变mysql执行的参数

官方网站上说
引用
Invoke mysql_secure_installation without arguments:

我想大概是不可以带参数执行吧
但我还是试了试,不行
后来发现这是个bug
引用
http://bugs.mysql.com/bug.php?id=27671

很多人都想往这里面加参数执行
这是解决办法
引用
http://lists.mysql.com/commits/27214

用diff比较出来的结果,自己改改就可以了
但是他这是不修改root密码版本的,root密码手动改吧

改完之后就可以mysql_secure_installation /etc/mysql/my.cnf
执行了
这是我执行的日志
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

NOTE: You provided an existing client configuration file!
      This triggers an assumption that you know what you're doing!

In order to log into MySQL to secure it, we'll need the current
password for the root user. The file
    /etc/mysql/my.cnf
must include this password!

You will not be able to change the root password with this script.
If you have not set a root password, please do so manually.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
ERROR 1010 (HY000) at line 1: Error dropping database (can't rmdir './test/', errno: 17)
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!
// 这里报了个错,没有关系,自己手动删掉就OK了

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...
[: 383: x/etc/mysql/my.cnf: unexpected operator
// 这里也报了个错,估计是权限的关系

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

当然到现在还没有改root的密码
要改也很简单
UPDATE user SET Password=PASSWORD('root_pwd') WHERE User='root'

或者以GUI方式登录进去,直接Edit,但是那个是要通过PASSWORD函数生成的字符串哦,否则你就只能找回密码了

到现在所有的东西都搞定了吧,重启MySQL试试看都正常不?

总结其实网上有很多东西你回头来想都写的是正确的,只是我们阅读起来会有些片面的理解,所以还是以官方文档为准,参考网上的最好

需要理解与MySQL服务器通信一般有两种方式,unix或linux可以通过socket和tcpip,socket优点是速度快,但是只能本机有效

我这也只是些记录,不是完整的教程,误导人的地方请指出
引用
附带一些命令:
启动:sudo mysqld_safe --user=mysql &
关闭:mysqladmin shutdown -u root -p

查看mysql正在使用哪个socket:
netstat -ln | grep mysql

查看进程:
ps -ef | grep mysql

设置了root密码之后又丢失了可以这样

如果忘记了密码,mysql服务器又在运行的话就直接杀进程
killall mysqld

>mysqld_safe --skip-grant-tables &
>mysql -u root -p // 直接回车,这个时候不需要密码
>user mysql;
>update user set password=password("new_passwd") where user="root"; // 这个password函数一定需要
>flush privileges;

之后退出重启mysql


如果缺少包的话一一装上就可以了
比如
引用
libaio.so.1
sudo apt-get install libaio-dev

另外Linux那个SQL Browser问题比较多啊

for 5.5 utf-8
my.cnf
mysqld
character-set-server = utf8

附件是我在用的my.cnf和mysql_secure_installation,mysql_secure_installation是根据bug解决方案改过来的
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics