mysql的安裝及yum的使用
環境
虛擬機器系統:Red Hat Enterprise Linux Server release 6.3 (64位)
原始碼包:mysql-5.5.33.tar.gz 下載地址:
cmake-2.8.10.2.tar.gz 下載地址:
一、安裝前的準備
yum的安裝:
首先將RedHat6.3系統ISO檔案載入到虛擬機器中。
mount /dev/cdrom /media/
首先建立倉庫檔名為rhelu4.repo:
vim /etc/yum.repos.d/rhelu4.repo
[Server]
name=Server
baseurl=file:///media/Server ###URL地址,也可為ftp、http等
gpgcheck=0 ###0為禁止簽名檢查
清除當前的快取:
[[root@test Server]# yum clean all
Loaded plugins: aliases, changelog, downloadonly, kabi, presto, product-id, refresh-packagekit, security, subscription-manager, tmprepo, verify, versionlock
Updating certificate-based repositories.
Unable to read consumer identity
Loading support for Red Hat kernel ABI
Cleaning repos: Server
Cleaning up Everything
0 delta-package files removed, by presto
檢視當前倉庫有沒有需要的想要的Server倉庫
[root@test media]# yum repolist
Loaded plugins: aliases, changelog, downloadonly, kabi, presto, product-id, refresh-packagekit, security, subscription-manager, tmprepo, verify, versionlock
Updating certificate-based repositories.
Unable to read consumer identity
Loading support for Red Hat kernel ABI
Server | 4.0 kB 00:00 ...
Server/primary_db | 3.1 MB 00:00 ...
repo id repo name status
Server Server 3,585
repolist: 3,585
刪除系統中自帶的MySQL client以及server
yum -y remove mysql mysql-server
rpm -qa | grep mysql
刪除系統自帶配置檔案
rm -rf /etc/my.cnf
安裝MySQL依賴檔案
yum -y install ncurses-devel bison openssl-devel gcc gcc-c++ make
二、cmake的安裝
MySQL 5.5版本以後需要用cmake來安裝
安裝cmake:
檢視yum中的cmake
yum list | grep cmake
檢視cmake系統中是否已經安裝
rpm qa | grep cmake
解壓cmake
tar xvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
安裝cmake
# ./configure ###指定路徑(cmake不建議指定路徑)--prefix /user/local/cmake
# make
# make install
# cmake --version
三、安裝MySQL
# groupadd mysql
# useradd -M -g mysql -s /sbin/nologin mysql
# tar -xvf mysql-5.5.33.tar.gz
# cd mysql-5.5.33
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DSYSCONFDIR=/etc \
-DINSTALL_MANDIR=/usr/share/man \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1
# make
# make install
四、MySQL的配置
# cd /usr/local/mysql
更改使用者
# chown -R mysql:mysql mysql/
初始化
# ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/
配置:
# cp support-files/my-huge.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start
檢視MySQL程式
# netstat -tnlp | grep mysql
#ps aux | grep mysqld
設定環境變數:
# echo export PATH=$PATH:/usr/local/mysql/bin >> /etc/profile
# source /etc/profile
檢視環境變數:
root@test mysql]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
五、登陸MySQL
設定初始化後的MySQL密碼:
# mysqladmin -uroot password 'mysql'
# mysql -uroot –pmysql
六、遠端連線設定
檢視可以遠端的主機:
mysql> Select user,password,host from mysql.user;
+------+-------------------------------------------+-----------+
| user | password | host |
+------+-------------------------------------------+-----------+
| root | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA | localhost |
| root | | test |
| root | | 127.0.0.1 |
| root | | ::1 |
| | | localhost |
| | | test |
+------+-------------------------------------------+-----------+
6 rows in set (0.00 sec)
賦許可權:
mysql> grant all on *.* to user1@'%' identified by '123';
從遠端軟體可以使用user1 連線此資料庫。
七、忘記密碼
#vim /etc/my.cnf
[mysqld]
skip-grant-table
#service mysqld restart
#mysql
mysql>update mysql.user set password=password("123") where user="root" and host="localhost";
mysql>flush privileges;