yum
rpm包
常規編譯安裝
cmake安裝
二進制包免安裝mysql
我的使用
yum或rpm包安裝c++
企業使用
多用常規編譯和cmake及二進制包免安裝sql
數量少的話
5.1.x版本選擇使用常規編譯安裝
5.5.x版本選擇使用cmake方式編譯安裝vim
數量多的話
直接使用二進制包免安裝服務器
首先查看系統環境app
[root@localhost ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@localhost ~]# uname -r 2.6.32-431.el6.x86_64 [root@localhost ~]# uname -m x86_64
在安裝cmake軟件,須要安裝gcc和gcc-c++dom
編譯安裝完cmake後,須要安裝依賴包tcp
記住先要安裝用戶和組
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd mysql -s /sbin/nologin -M -g mysqlide
依賴包安裝完後,cd進入mysql的目錄進行cmake操做post
cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \ -DMYSQL_DATADIR=/application/mysql-5.5.32/data \ -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/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 \ -DWITH_FAST_MUTEXES=1 \ -DWITH_ZLIB=bundled \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_READLINE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_DEBUG=0 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ 貌似由於64位主機編譯不過去!!! -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DEXTRA_CHARSETS=all ``` 執行成功返回下面代碼
Build files have been written to: /root/lamp/mysql-5.5.32
make && install 安裝完成
[100%] Built target my_safe_process #此處make完成
....
....
....
-- Installing: /application/mysql-5.5.32/support-files/solaris/postinstall-solaris #此處make install 完成
創建link
創建my.cnf
[root@localhost /]# cp /application/mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
cp:是否覆蓋"/etc/my.cnf"? y
配置環境變量
echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile
tail -l /etc/profile
source /etc/profile
echo $PATH
給mysql用戶和mysql用戶組受權
初始化db腳本,假若有兩個ok,就證實成功
[root@localhost /]# cd /application/mysql/scripts/
[root@localhost scripts]# ./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
修改hosts文件
加入www
加入mysqld腳本
加入mysqld腳本執行權限
chmod +x /etc/init.d/mysqld
執行mysqld運行
[root@localhost scripts]# /etc/init.d/mysqld start
Starting MySQL... [肯定]
[root@localhost scripts]# netstat -lntup | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2671/mysqld
進入mysql服務器,若是以前配置了環境變量了,就能夠執行mysql命令
刪除空用戶
mysql> select user,host from mysql.user; | |
---|---|
user | host |
+------+-----------------------+ | |
root | 127.0.0.1 |
root | ::1 |
localhost | |
root | localhost |
localhost.localdomain | |
root | localhost.localdomain |
6 rows in set (0.00 sec)
mysql> delete from mysql.user where user ='';
Query OK, 2 rows affected (0.09 sec)
mysql> select user,host from mysql.user; | |
---|---|
user | host |
+------+-----------------------+ | |
root | 127.0.0.1 |
root | ::1 |
root | localhost |
root | localhost.localdomain |
4 rows in set (0.00 sec)
mysql>
受權system管理員
mysql> grant all privileges on . to system@'localhost' identified by 'longjq' with grant option;
Query OK, 0 rows affected (0.00 sec)
修改mysql密碼
/application/mysql//bin/mysqladmin -u root password '123456'
/application/mysql//bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
加入啓動管理
[root@localhost scripts]# chkconfig --list mysqld
mysqld 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉`
登陸不了mysql?刪除文件,從新初始化
# mysql access denied for user 'localhost'...... # pkill mysqld # lsof -i :3306 # rm -fr /application/mysql/data/* # /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
字符集錯誤?
[root@localhost scripts]# cat /etc/sysconfig/i18n #LANG="zh_CN.GB18030"#這裏改爲zh_CN.UTF-8 LANG="zh_CN.UTF-8"