由於MySQL的版本不同,所以會有不同的安裝方式。在下以Linux系統下MySQL5.1.19版本為例,進行安裝,初學還望指正。
一、安裝編譯軟件(簡單的yum安裝)
gcc
gcc-c++
ncurses
ncurses-devel
cmake
二、修改hosts可以解析主機名
echo "127.0.0.1 `hostname`" >> /etc/hosts
三、編譯安裝
# tar xvf mysql-5.5.19.tar.gz
# cd mysql-5.5.19
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
# make && make install
四、生成配置文件
# cp /root/mysql-5.5.19/support-files/my-large.cnf /etc/my.cnf
# vim /etc/my.cnf
[mysqld]
datadir = /usr/local/mysql/data
五、新建一個運行MySQL的用戶
# groupadd mysql
# useradd -r -g mysql -s /sbin/nologin mysql
六、初始化
#/home/mysql-5.5.19/scripts/mysql_install_db \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data --user=mysql
七、修改MySQL目錄權限
# chown -R root.mysql /usr/local/mysql
# chmod -R 777 /usr/local/mysql/data
八、啟動MySQL
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
九、導出啟動程序
# cp /home/mysql-5.5.19/support-files/mysql.server /etc/init.d/mysqld
# chymod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# service mysqld start
十、導出MySQL的登錄程序
# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
PS:
登錄MySQL:
/usr/bin/mysql -u root -p密碼