萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> linux中安裝mysql數據庫的2種方法

linux中安裝mysql數據庫的2種方法

安裝mysql數據庫在linux系統中有兩種安裝方法,一種是編譯安裝mysql 另一種是 免編譯式安裝mysql了,希望下文對各位有幫助.

編譯安裝mysql

安裝前准備

如果mysql用戶不存在,那麼添加mysql用戶

groupadd mysql
useradd -g mysql mysql

mysql編譯安裝

wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.70.tar.gz
tar -zxvf mysql-5.1.70.tar.gz
cd mysql-5.1.70

yum install ncurses ncurses-devel
./configure  '--prefix=/usr/local/mysql' '--without-debug' '--with-charset=utf8' '--with-extra-charsets=all' '--enable-assembler' '--with-pthread' '--enable-thread-safe-client' '--with-mysqld-ldflags=-all-static' '--with-client-ldflags=-all-static' '--with-big-tables' '--with-readline' '--with-ssl' '--with-embedded-server' '--enable-local-infile' '--with-plugins=innobase'
make
make install

到此mysql就安裝到了/usr/local/mysql路徑下,下面開始mysql的配置工作
------------------------------------

安裝mysql選項文件

   
cp support-files/my-medium.cnf /etc/my.cnf

mysql設置開機自啟動

cp -r support-files/mysql.server /etc/init.d/mysqld 
/sbin/chkconfig --del mysqld
/sbin/chkconfig --add mysqld
配置權限表

chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql
啟動mysql

/etc/init.d/mysqld start

這一步可能會報錯

/etc/init.d/mysqld: line 260: my_print_defaults: command not found
/etc/init.d/mysqld: line 263: my_print_defaults: command not found
/etc/init.d/mysqld: line 270: @HOSTNAME@: command not found
/etc/init.d/mysqld: line 279: @HOSTNAME@: command not found
/etc/init.d/mysqld: line 292: cd: @prefix@: No such file or directory
Starting MySQLCouldn't find MySQL manager (@bindir@/mysqlmanager) or server (@bindir@/mysqld_safe) [FAILED]

因為路徑沒有設置,請重啟確認上面配置工作是否都完成,一般是configure後沒有make和make install。

mysql初始化配置:

export PATH=/usr/local/mysql/bin:$PATH
/usr/local/mysql/bin/mysql_secure_installation

mysql如何導入舊的數據:

直接拷貝數據庫文件夾到數據目錄下然後執行

/usr/local/mysql/bin/mysqladmin -u root -p flush-tables


mysql安裝過程中問題

1.
make[2]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
make[3]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
make[3]: Nothing to be done for `install-exec-am.
make INSTALL_TO_DIR="/usr/local/mysql/mysql-test" install_test_files
make[4]: Entering directory `/down/webinstall/mysql-5.1.57/mysql-test
時間較長

MYSQL安裝到這裡卡了很久,可能以為出錯了,實際上MYSQL已經安裝成功了,它這步過段時間就會好了,是mysql在自我編譯測試造成的。

2.checking for termcap functions library... configure: error: No curses/termcap library found
yum install ncurses ncurses-devel

3.Starting MySQL.Manager of pid-file quit without updating fi[FAILED]

啟動數據庫之前,需要先配置權限表,其中/usr/local/mysql為mysql的安裝目錄
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql

上面安裝mysql是通過編譯的方式安裝,此次不進行編譯,直接安裝。


[root@hk tools]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
[root@hk tools]# tar zxf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
[root@hk tools]# mv mysql-5.6.16-linux-glibc2.5-x86_64 /opt/
[root@hk opt]# mv mysql-5.6.16-linux-glibc2.5-x86_64 mysql
[root@hk opt]# /usr/sbin/useradd mysql -s /sbin/nologin -M
[root@hk opt]# cd mysql/
[root@hk mysql]# /opt/mysql/scripts/mysql_install_db --basedir=/opt/mysql/ --datadir=/opt/mysql/data --user=mysql
[root@hk mysql]# mv /etc/my.cnf /etc/my.cnf.backup
[root@hk mysql]# sed -i 's#\# socket = .....# socket = /tmp/mysql.sock#g' my.cnf
[root@hk mysql]# cp /opt/mysql/my.cnf /etc/my.cnf
[root@hk mysql]# /opt/mysql/support-files/mysql.server start
[root@hk mysql]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  
tcp        0      0 :::3306                     :::*                        LISTEN      28104/mysqld 
[root@hk mysql]#  /opt/mysql/bin/mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) #看下面的sock的配置
[root@hk mysql]# sed -i 's#\# socket = .....# socket = /tmp/mysql.sock#g' my.cnf
[root@hk mysql]# /opt/mysql/bin/mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)   #居然報錯
[root@hk mysql]# /opt/mysql/bin/mysqld_safe --skip-grant-tables &
[1] 30062
mysql> update mysql.user set password=PASSWORD('admin123') where user='root';    #設置密碼
mysql> flush privileges;
[root@hk mysql]# skill 30194
[root@hk mysql]# 140601 00:14:38 mysqld_safe mysqld from pid file /opt/mysql/data/hk.t4x.org.pid ended
[1]+  Done                    /opt/mysql/bin/mysqld_safe --skip-grant-tables
[root@hk mysql]# /opt/mysql/bin/mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)    #錯誤依舊
[root@hk mysql]# vim /usr/local/mysql/support-files/mysql.server   #配置文件中默認配置目錄是/usr/local/mysql
[root@hk mysql]# ln -s /opt/mysql /usr/local/mysql    #設置軟連接
[root@hk mysql]# /usr/local/mysql/bin/mysql -uroot -p'admin123'
mysql>

copyright © 萬盛學電腦網 all rights reserved