標籤:安裝mysql
安裝MySql方法有多種方式,如:
| 序號 |
MySql安裝方式 |
特點說明 |
| 1 |
yum/rpm包安裝 |
特點是簡單、速度快,但是沒法定製安裝,入門新手常用這種方式 |
| 2 |
二進位安裝 |
解壓軟體,簡單配置後就可以使用,不用安裝,速度較快,專業DNA喜歡這種方式。軟體名如:mysql-5.5.32-linux2.6_x86_64.tar.gz |
| 3 |
源碼編譯安裝 |
特點是可以定製安裝,但是安裝時間長,例如:字元集安裝路徑,等等。軟體名稱如:mysql-5.5.32.tar.gz |
| 4 |
源碼軟體結合yum/rpm安裝 |
把源碼軟體製作成符合要求的rpm,放到yum倉庫裡,然後通過yum來安裝。結合了上面1和3的優點,即安裝快速,可做生意定製參數,但是安裝者也需要具有更深能力 |
下面示範yum和編譯安裝:
一、yum安裝
1、關閉iptables
[[email protected] ~]# /etc/init.d/iptables stopiptables: Setting chains to policy ACCEPT: filter [ OK ]iptables: Flushing firewall rules: [ OK ]iptables: Unloading modules: [ OK ][[email protected] ~]# /etc/init.d/iptables stop[[email protected] ~]# chkconfig iptables off
2、關閉SELinux
[[email protected] ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config[[email protected] ~]# setenforceusage: setenforce [ Enforcing | Permissive | 1 | 0 ][[email protected] ~]# setenforce 0[[email protected] ~]# getenforcePermissive
3、安裝mysql
[[email protected] ~]# yum -y install mysql mysql-server mysql-develLoaded plugins: fastestmirror, securitybase | 3.7 kB 00:00 base/primary_db | 4.6 MB 00:30 extras | 3.4 kB 00:00 extras/primary_db | 37 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 5.2 MB 00:43...略[[email protected] ~]# chkconfig mysqld on #開機啟動[[email protected] ~]# chkconfig --list | grep mysqld#查詢是否開機啟動mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off[[email protected] ~]# service mysqld start#啟動服務Starting mysqld: [ OK ] [[email protected] ~]# mysql #進入mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> CREATE DATABASE wordpress;#建立一個名稱為wordpress的資料庫Query OK, 1 row affected (0.00 sec)mysql> select user,host,password from mysql.user; #查詢使用者等資訊+------+-----------+----------+| user | host | password |+------+-----------+----------+| root | localhost | || root | mysql | || root | 127.0.0.1 | || | localhost | || | mysql | |+------+-----------+----------+5 rows in set (0.00 sec)mysql> set password for [email protected]=password(‘root‘);#查詢使用者的密碼,都為空白,用上面的命令設定root的密碼為rootQuery OK, 0 rows affected (0.00 sec)mysql> select user,host,password from mysql.user; #重新查詢發現password下面已有密碼資訊+------+-----------+-------------------------------------------+| user | host | password |+------+-----------+-------------------------------------------+| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B || root | mysql | || root | 127.0.0.1 | || | localhost | || | mysql | |+------+-----------+-------------------------------------------+5 rows in set (0.00 sec)mysql> exitBye[[email protected] ~]#[[email protected] ~]# mysql -u root -p #用新密碼登入Enter password: #填寫密碼Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.1.73 Source distribution...略mysql> exit[[email protected] ~]#[[email protected] ~]# cat /etc/my.cnf #/etc/my.cnf是mysql的主設定檔[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[[email protected] ~]#[[email protected] ~]# ls -l /var/lib/mysql/#mysql資料庫的資料庫檔案存放位置total 20492-rw-rw----. 1 mysql mysql 10485760 May 16 22:30 ibdata1-rw-rw----. 1 mysql mysql 5242880 May 16 22:30 ib_logfile0-rw-rw----. 1 mysql mysql 5242880 May 16 22:30 ib_logfile1drwx------. 2 mysql mysql 4096 May 16 22:30 mysqlsrwxrwxrwx. 1 mysql mysql 0 May 16 22:30 mysql.sockdrwx------. 2 mysql mysql 4096 May 16 22:30 testdrwx------. 2 mysql mysql 4096 May 16 22:33 wordpress[[email protected] ~]#[[email protected] ~]# ls /var/log/#記錄檔存放位置anaconda.ifcfg.log anaconda.yum.log dmesg mysqld.log tallyloganaconda.log audit dmesg.old ntpstats wtmpanaconda.program.log boot.log dracut.log prelink yum.loganaconda.storage.log btmp lastlog saanaconda.syslog ConsoleKit maillog secureanaconda.xlog cron messages spooler[[email protected] ~]#[[email protected] ~]# netstat -lntup|grep 3306#查看mysql連接埠偵聽狀態tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2053/mysqld[[email protected] ~]#
基本命令
show databases; //查看系統已存在的資料庫
use databasesname; //選擇需要使用的資料庫
drop database databasename; //刪除選定的資料庫
exit //退出資料庫的串連
create database test01; //建立名為test的資料庫
show tables; // 列出當前資料庫下的表
其他基本的增刪改查使用標準SQL即可
開放遠程登入許可權
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘root‘ WITH GRANT OPTION;
FLUSH PRIVILEGES;
參考:
老男孩
http://blog.csdn.net/xxd851116/article/details/22947891
http://www.xxlinux.com/article/development/database/20121106/18532.html
本文出自 “寫給自己的部落格” 部落格,請務必保留此出處http://zhaodongwei.blog.51cto.com/4233742/1773898
Centos6.5安裝MySql