您好,登錄后才能下訂單哦!
1、安裝方法
mysql安裝常見的方法有四種
序號 | 安裝方式 | 說明 |
1 | yum\rpm | 簡單、快速,不能定制參數(shù) |
2 | 二進制 | 解壓,簡單配置就可使用 免安裝 mysql-a.b.c-linux2.x-x86_64.tar.gz |
3 | 源碼編譯 | 可以定制參數(shù),安裝時間長 mysql-a.b.c.tar.gz |
4 | 源碼制成rpm包 | 把源碼制作成符合要求的rpm,通過yum安裝 |
2、安裝步驟
創(chuàng)建mysql 用戶
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql (不創(chuàng)建家目錄)
獲取軟件包
可以選擇國內(nèi)的sohu鏡像站點下載
http://mirrors.sohu.com/mysql/ 可以選擇自己要使用的其他版本
http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.55-linux2.6-x86_64.tar.gz
二進制安裝
[root@bj-web-001 opt]# cd /opt/
[root@bj-web-001 opt]#wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.55-linux2.6-x86_64.tar.gz
[root@bj-web-001 opt]# tar xf mysql-5.5.55-linux2.6-x86_64.tar.gz
[root@bj-web-001 opt]# ln -s mysql-5.5.55-linux2.6-x86_64 mysql
[root@bj-web-001 opt]# ls -l mysql
lrwxrwxrwx 1 root root 28 6月 27 22:13 mysql -> mysql-5.5.55-linux2.6-x86_64
[root@bj-web-001 mysql]# ls -l support-files/*.cnf
-rw-r--r-- 1 7161 31415 4691 3月 18 13:14 support-files/my-huge.cnf
-rw-r--r-- 1 7161 31415 19759 3月 18 13:14 support-files/my-innodb-heavy-4G.cnf
-rw-r--r-- 1 7161 31415 4665 3月 18 13:14 support-files/my-large.cnf
-rw-r--r-- 1 7161 31415 4676 3月 18 13:14 support-files/my-medium.cnf
-rw-r--r-- 1 7161 31415 2840 3月 18 13:14 support-files/my-small.cnf
[root@bj-web-001 mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
[root@bj-web-001 ~]# chown -R mysql.mysql /opt/mysql/
[root@bj-web-001 ~]# ll /opt/mysql/
總用量 72
drwxr-xr-x 2 mysql mysql 4096 6月 27 22:08 bin
-rw-r--r-- 1 mysql mysql 17987 3月 18 12:41 COPYING
drwxr-xr-x 3 mysql mysql 4096 6月 27 22:08 data
drwxr-xr-x 2 mysql mysql 4096 6月 27 22:08 docs
drwxr-xr-x 3 mysql mysql 4096 6月 27 22:08 include
-rw-r--r-- 1 mysql mysql 301 3月 18 12:41 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 6月 27 22:09 lib
drwxr-xr-x 4 mysql mysql 4096 6月 27 22:08 man
drwxr-xr-x 10 mysql mysql 4096 6月 27 22:09 mysql-test
-rw-r--r-- 1 mysql mysql 2496 3月 18 12:41 README
drwxr-xr-x 2 mysql mysql 4096 6月 27 22:08 scripts
drwxr-xr-x 27 mysql mysql 4096 6月 27 22:09 share
drwxr-xr-x 4 mysql mysql 4096 6月 27 22:08 sql-bench
drwxr-xr-x 2 mysql mysql 4096 6月 27 22:08 support-files
[root@bj-web-001 ~]# /opt/mysql/scripts/mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data/ --user=mysql
[root@bj-web-001 ~]# tree /opt/mysql/data/
/opt/mysql/data/
├── mysql
│ ├── columns_priv.frm
│ ├── columns_priv.MYD
│ ├── columns_priv.MYI
│ ├── db.frm
│ ├── db.MYD
│ ├── db.MYI
│ ├── event.frm
│ ├── event.MYD
│ ├── event.MYI
│ ├── func.frm
│ ├── func.MYD
│ ├── func.MYI
[root@bj-web-001 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@bj-web-001 mysql]# chmod +x /etc/init.d/mysqld
[root@bj-web-001 mysql]# sed -i 's#/usr/local/mysql#/opt/mysql#g' /opt/mysql/bin/mysqld_safe /etc/init.d/mysqld
[root@bj-web-001 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/opt/mysql/data/bj-web-001.err'.
. SUCCESS!
還可以使用 (2選1)
[root@bj-web-001 mysql]# /opt/mysql/bin/mysqld_safe --user=mysql &
[root@bj-web-001 mysql]# netstat -ntpl|grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 58844/mysqld
要是啟動失敗,需要查看日志
[root@bj-web-001 mysql]# tail -f data/bj-web-001.err
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
設(shè)置開機啟動
[root@bj-web-001 data]# chkconfig --add mysqld
[root@bj-web-001 data]# chkconfig mysqld on
[root@bj-web-001 data]# chkconfig --list mysqld
mysqld 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
配置環(huán)境變量
[root@bj-web-001 data]# echo 'export PATH=/opt/mysql/bin:$PATH' >> /etc/profile
[root@bj-web-001 data]# tail -1 /etc/profile
export PATH=/opt/mysql/bin:$PATH
[root@bj-web-001 data]# source /etc/profile
[root@bj-web-001 data]# echo $PATH
/opt/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
測試登錄
[root@bj-web-001 data]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.55 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> \q
Bye
設(shè)置密碼
[root@bj-web-001 data]# mysqladmin -u root password '123456'
[root@bj-web-001 data]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@bj-web-001 data]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.55 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
刪除無用賬戶
mysql> DELETE FROM mysql.user WHERE user = ''; [刪除匿名帳戶]
mysql> select user,host from mysql.user;
+------+------------+
| user | host |
+------+------------+
| root | 127.0.0.1 |
| root | ::1 |
| | bj-web-001 |
| root | bj-web-001 |
| | localhost |
| root | localhost |
+------+------------+
6 rows in set (0.00 sec)
mysql> drop user "root"@"::1";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ""@"localhost";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ""@"bj-web-001";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user "root"@"bj-web-001";
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
刪除無用數(shù)據(jù)庫
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql>
至此,二進制安裝mysql數(shù)據(jù)庫完成。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。