Ubuntu二進制安裝MySQL 5.5

下載地址
[quote]http://mysql.oss.eznetsols.org/Downloads/MySQL-5.5/mysql-5.5.8-linux2.6-i686.tar.gz[/quote]
下載完按照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.

按着網上的
[quote]http://scnjl.iteye.com/blog/655432[/quote]
[quote]安裝或者重新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

[/quote]
改了再執行
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相關的配置文件

[quote]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[/quote]

創建用戶和組
創建鏈接
授權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參數的意義,參見[quote]http://dev.mysql.com/doc/refman/5.5/en/unix-postinstallation.html[/quote]
[quote]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”.[/quote]
就是說你可以以普通用戶來啓動MySQL,如果你當前登錄操作系統的是root用戶,那麼你就可以帶--user參數來以普通身份啓動,如果你就是以mysql用戶登錄操作系統的,那你這個參數就可以省略
所以不管這樣,這個--user參數都可以帶上
&符號是後臺啓動
可以參看下[quote]How to Run MySQL as a Normal User(http://dev.mysql.com/doc/refman/5.5/en/changing-mysql-user.html)[/quote]
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
[quote]http://dev.mysql.com/doc/refman/5.5/en/option-files.html[/quote]
其中mysql.sock只是個本地化加速的東西,可以不要
但沒有他的話不能用mysqladmin和mysql_secure_installation這些命令

網上一些帖子說要麼這個文件是放在其他的地方了,通過引入鏈接就可以搞定,可是我的額機器裏面根本就沒有這個文件,後來才知道這個文件是動態生成的
[quote]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[/quote]
但我們已經可以登錄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下面的
[quote]socket = /etc/mysql/mysql.sock[/quote]
之後保存,然後再重啓就會在/etc/mysql/生成mysql.sock
(最後我試了下,只有先sudo -i切換到root下面,再執行纔有生成,而普通的sudo sudo mysqld_safe --user=mysql &並沒有立即生成sock這個文件,有時候又不需要這麼做,不是很懂,希望高手指點)

這樣mysqladmin可以用了,還剩個mysql_secure_installation沒有執行,實際這個內容就是我們在windows裏面裝完之後最後一步設置,像什麼禁止root遠程登錄,禁止匿名賬戶,修改root密碼等等
先不管這個了

先來裝GUI客戶端下載之後解壓到某個位置,拷貝.desktop到桌面之後,還不能直接執行,會提示“未信任的應用程序啓動器”
這時候只要右擊,屬性,權限,允許以程序執行文件,打鉤就可以了
再次雙擊就可以執行了,第一次比較慢
安裝方法參見:[quote]http://dev.mysql.com/doc/administrator/en/install-generic-tarball.html[/quote]
圖形化界面登錄的時候,點擊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路徑呢
[quote]socket = /etc/mysql/mysql.sock[/quote]
當然此刻比較簡單的辦法就是往/tmp文件夾下做個符號鏈接,但是還是要找原因
讓他直接去搜索/etc下的不更好
於是看見find_mysql_client
帶有這麼一個東西 --no-defaults
這大概就是mysql的參數吧
果斷man mysql
貌似沒有找到,於是mysql --help,看到了這麼段
[quote]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.
[/quote]
先是說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執行的參數

官方網站上說
[quote]Invoke mysql_secure_installation without arguments:[/quote]
我想大概是不可以帶參數執行吧
但我還是試了試,不行
後來發現這是個bug
[quote]http://bugs.mysql.com/bug.php?id=27671[/quote]
很多人都想往這裏面加參數執行
這是解決辦法
[quote]http://lists.mysql.com/commits/27214[/quote]
用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優點是速度快,但是隻能本機有效

我這也只是些記錄,不是完整的教程,誤導人的地方請指出
[quote]附帶一些命令:
啓動: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[/quote]

如果缺少包的話一一裝上就可以了
比如
[quote]libaio.so.1
sudo apt-get install libaio-dev[/quote]
另外Linux那個SQL Browser問題比較多啊

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

附件是我在用的my.cnf和mysql_secure_installation,mysql_secure_installation是根據[url=http://lists.mysql.com/commits/27214]bug解決方案[/url]改過來的
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章