從MySQL5.5 開始就要用cmake安裝,本次安裝的版本為mysql-5.5.22.tar.gz
#准備工作 yum install -y gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel ncurses-devel cmake bison #添加mysql用戶、組 groupadd mysql useradd -r -g mysql mysql mkdir /usr/local/mysql/ #創建mysql安裝目錄 mkdir /data/mysql #創建數據存放目錄 #配置編譯安裝mysql tar zxvf mysql-5.5.13.tar.gz cd mysql-5.5.13 cmake . \ #開始編譯 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安裝到/usr/local/mysql目錄 -DMYSQL_DATADIR=/data/mysql \ #數據存放到/data/mysql目錄 -DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock \ #sock存放到/data/mysql目錄 -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #innoDB引擎 -DENABLED_LOCAL_INFILE=1 \ -DDEFAULT_CHARSET=utf8 \ #字符集 -DDEFALUT_CHARSETS=all \ #支持所有字符集 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DDEFAULT_COLLATION=utf8_general_ci \ #字符集校驗 -DMYSQL_USER=mysql \ -DEXTRA_CHARSETS=all \ -DMYSQL_TCP_PORT=3306 \ -DWITH_DEBUG=0\ make make install #改變目錄權限 chown -R mysql /usr/local/mysql chgrp -R mysql /usr/local/mysql chown -R mysql /data/mysql chgrp -R mysql /data/mysql scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --ldata=/data/mysql #初始化數據庫 chown -R root /usr/local/mysql #可選 cp support-files/my-medium.cnf /etc/my.cnf #復制配置文件 cp support-files/mysql.server /etc/init.d/mysqld #復制啟動腳本 chmod 755 /etc/init.d/mysqld #將mysql的啟動服務添加到系統服務中 chkconfig --add mysqld #添加系統服務 chkconfig mysqld on #添加開機啟動 chkconfig --levels 245 mysqld off 或 echo "/usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/data/mysql/ &" >> /etc/rc.loacl export PATH=$PATH:/usr/local/mysql/bin #添加環境變量 echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile #啟動mysql service mysqld start/stop 或 /usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/data/mysql/ & 適用於沒有自啟動文件的 #啟動mysql,看是否成功 netstat -tnl|grep 3306
手冊中提到的安裝方法:
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: /usr/local/mysql//bin/mysqladmin -u root password 'new-password' /usr/local/mysql//bin/mysqladmin -u root -h localhost password 'new-password' Alternatively you can run: /usr/local/mysql//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 /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!
默認的mysql安裝目錄
shell> groupadd mysql shell> useradd -r -g mysql mysql # Beginning of source-build specific instructions shell> tar zxvf mysql-VERSION.tar.gz shell> cd mysql-VERSION shell> cmake . shell> make shell> make install # End of source-build specific instructions # Postinstallation setup shell> cd /usr/local/mysql shell> chown -R mysql . shell> chgrp -R mysql . shell> scripts/mysql_install_db --user=mysql shell> chown -R root . shell> chown -R mysql data # Next command is optional shell> cp support-files/my-medium.cnf /etc/my.cnf shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server
修改默認密碼(默認無密碼):
use mysql; update user set password=password('123456') where user='root' flush privileges;
安裝過程中的一些說明
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: /usr/local/mysql//bin/mysqladmin -u root password 'new-password' /usr/local/mysql//bin/mysqladmin -u root -h localhost password 'new-password' Alternatively you can run: /usr/local/mysql//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 /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!
#mysql 默認讀取配置文件 順序
/etc/my.cnf ~/.my.cnf /usr/local/mysql/etc/my.cnf
#查看編譯參數 sudo cat /usr/local/mysql/bin/mysqlbug|grep configure
提示mysql.sock找不到的解決
原因:
當php連接mysql時如果是本地連接(127.0.0.1 或 localhost )時,會用到 pdo_mysql.default_socket= 參數(如果是pdo連接數據庫),
該默認參數為 pdo擴展編譯時的參數
[Pdo_mysql] ; If mysqlnd is used: Number of cache slots for the internal result set cache ; http://php.net/pdo_mysql.cache_size pdo_mysql.cache_size = 2000 ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. ; http://php.net/pdo_mysql.default-socket pdo_mysql.default_socket=
參考文章地址:
http://wowking.blog.51cto.com/1638252/1037609
http://blog.csdn.net/westmaniac/article/details/6535000