Solaris下MySQL5安裝筆記

Solaris下MySQL 5 安裝筆記

 

就是按照官方的《MySQL5.1參考手冊》2.7節“在其它類Unix系統中安裝MySQL”步驟安裝的,還是官方的資料可靠,自己稍微整理一下,方便查閱。

Unix
$ uname -a
SunOS fs-cluster1 5.8 Generic_108528-13 sun4u sparc SUNW,Sun-Fire-280R

MySQL:
mysql-5.0.45-solaris8-sparc-64bit.tar.gz

一、為mysqld增加一個登錄用戶和組:

# groupadd mysql

# useradd -d /opt/mysql -g mysql -m mysql


二、挑選一個你想解開分發包的目錄,進入該目錄。在下面的例子中,我們將分發解包在“/usr/local”下:

# cd /usr/local


三、解包分發版,將創建安裝目錄。然后生成到該目錄的一個符號鏈接:

# gunzip < /opt/mysql-5.0.45-solaris8-sparc-64bit.tar.gz | tar -xvf -

# ln -s mysql-5.0.45-solaris8-sparc-64bit mysql


四、進入安裝目錄:

# cd mysql

你會在mysql目錄下發現幾個文件和子目錄,對安裝目的最重要的是“bin”和“scripts”子目錄。

·bin
這個目錄包含客戶端程序和服務器,你應該把這個目錄的完整路徑加到PATH環境變量,以便shell能正確的找到MySQL程序。

·scripts
這個目錄包含mysql_install_db腳本,用來初始化mysql數據庫的授權表,其中貯存了服務器訪問允許。


五、如果還沒有安裝MySQL,必須創建MySQL授權表:

# scripts/mysql_install_db --user=mysql
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:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h fs-cluster1 password 'new-password'
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!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
#

如果你用root運行命令,應當使用--user選項。選項的值應與你在第一步為運行服務器所創建的登錄賬戶相同。如果你用該用戶登錄來運行命令,可以省略--user選項。


六、將程序二進制的所有權改為root,數據目錄的所有權改為運行mysqld 的用戶:

# chown -R root .

# chown -R mysql data

# chgrp -R mysql .

第一個命令將文件的所有屬性改為root用戶。第二個命令將數據目錄的所有屬性改為mysql用戶。第三個命令將組屬性改為mysql組。

如果你喜歡在引導機器時自動啟動MySQL,可以拷貝support-files/mysql.server文件到系統有啟動文件的地方。

在所有東西被解包并且安裝以后,你應該初始化并且測試你的分發版。


七、可以用下列命令啟動MySQL服務器:

# bin/mysqld_safe --user=mysql &
[1]     13502
# Starting mysqld daemon with databases from /usr/local/mysql-5.0.45-solaris8-sparc-64bit/data

注釋:MySQL授權表中的賬戶開始沒有密碼。啟動服務器后,應當設置密碼。


八、其它設置

把/usr/local/mysql/bin放入環境變量PATH里。

直接登陸:

# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

修改密碼:

# mysqladmin -u root password 'root'

修改密碼后登陸方式:

# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.45 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>


九、數據庫起停

使用mysqladmin驗證服務器在運行中。以下命令提供了簡單的測試,可檢查服務器是否已經啟動并能響應連接:

# mysqladmin -uroot -proot version
mysqladmin Ver 8.41 Distrib 5.0.45, for sun-solaris2.8 on sparc
Copyright (C) 2000-2006 MySQL AB
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.0.45
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /tmp/mysql.sock
Uptime:                 13 min 49 sec

Threads: 1 Questions: 9 Slow queries: 0 Opens: 12 Flush tables: 1 Open tables: 6 Queries per second avg: 0.011


關閉服務器:

# mysqladmin -uroot -proot shutdown


重啟服務器:

# mysqld_safe --user=mysql &
[1]     13583
# Starting mysqld daemon with databases from /usr/local/mysql/data

--End--