溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Centos6.5安裝MySql

發(fā)布時間:2020-07-03 21:50:33 來源:網(wǎng)絡(luò) 閱讀:528 作者:cix123 欄目:數(shù)據(jù)庫

安裝MySql方法有多種方式,如下圖:

序號MySql安裝方式特點說明
1yum/rpm包安裝特點是簡單、速度快,但是沒法定制安裝,入門新手常用這種方式
2二進制安裝解壓軟件,簡單配置后就可以使用,不用安裝,速度較快,專業(yè)DNA喜歡這種方式。軟件名如:mysql-5.5.32-linux2.6_x86_64.tar.gz
3源碼編譯安裝特點是可以定制安裝,但是安裝時間長,例如:字符集安裝路徑,等等。軟件名稱如:mysql-5.5.32.tar.gz
4源碼軟件結(jié)合yum/rpm安裝把源碼軟件制作成符合要求的rpm,放到y(tǒng)um倉庫里,然后通過yum來安裝。結(jié)合了上面1和3的優(yōu)點,即安裝快速,可做生意定制參數(shù),但是安裝者也需要具有更深能力

下面演示yum和編譯安裝:

一、yum安裝

1、關(guān)閉iptables

[root@mysql ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@mysql ~]# /etc/init.d/iptables stop
[root@mysql ~]# chkconfig iptables off

2、關(guān)閉SELinux

[root@mysql ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@mysql ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@mysql ~]# setenforce 0
[root@mysql ~]# getenforce
Permissive

3、安裝mysql

[root@mysql ~]# yum -y install mysql mysql-server mysql-devel
Loaded plugins: fastestmirror, security
base                                                     | 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
...略
[root@mysql ~]# chkconfig mysqld on                                  
#開機啟動
[root@mysql ~]# chkconfig --list | grep mysqld
#查詢是否開機啟動
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@mysql ~]# service mysqld start
#啟動服務(wù)
Starting mysqld:                                           [  OK  ]  
[root@mysql ~]# mysql                                                
#進入mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> CREATE DATABASE wordpress;
#創(chuàng)建一個名稱為wordpress的數(shù)據(jù)庫
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 root@localhost=password('root');
#查詢用戶的密碼,都為空,用上面的命令設(shè)置root的密碼為root
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;                   
#再次查詢發(fā)現(xiàn)password下面已有密碼信息
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | mysql     |                                           |
| root | 127.0.0.1 |                                           |
|      | localhost |                                           |
|      | mysql     |                                           |
+------+-----------+-------------------------------------------+
5 rows in set (0.00 sec)

mysql> exit
Bye
[root@mysql ~]#
[root@mysql ~]# mysql -u root -p                                    
#用新密碼登錄
Enter password:                                                     
#填寫密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
...略

mysql> exit
[root@mysql ~]#
[root@mysql ~]# cat /etc/my.cnf 
#/etc/my.cnf是mysql的主配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql ~]#
[root@mysql ~]# ls -l /var/lib/mysql/
#mysql數(shù)據(jù)庫的數(shù)據(jù)庫文件存放位置
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_logfile1
drwx------. 2 mysql mysql     4096 May 16 22:30 mysql
srwxrwxrwx. 1 mysql mysql        0 May 16 22:30 mysql.sock
drwx------. 2 mysql mysql     4096 May 16 22:30 test
drwx------. 2 mysql mysql     4096 May 16 22:33 wordpress
[root@mysql ~]#
[root@mysql ~]# ls /var/log/
#日志文件存放位置
anaconda.ifcfg.log    anaconda.yum.log  dmesg       mysqld.log  tallylog
anaconda.log          audit             dmesg.old   ntpstats    wtmp
anaconda.program.log  boot.log          dracut.log  prelink     yum.log
anaconda.storage.log  btmp              lastlog     sa
anaconda.syslog       ConsoleKit        maillog     secure
anaconda.xlog         cron              messages    spooler
[root@mysql ~]#
[root@mysql ~]# netstat -lntup|grep 3306
#查看mysql端口偵聽狀態(tài)
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2053/mysqld
[root@mysql ~]#

MySql密碼忘記后重新設(shè)置:

#多次輸入密碼均不對
[root@bogon ~]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@bogon ~]# /application/mysql//bin/mysqladmin -u root password '789@!@#'
#把root的mysql登錄密碼設(shè)置為789@!@#
[root@bogon ~]# mysql -u root -p
#輸入密碼789@!@#,進入mysql
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.32 Source distribution
Copyright (c) 2000, 2013, 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; //查看系統(tǒng)已存在的數(shù)據(jù)庫

use databasesname;   //選擇需要使用的數(shù)據(jù)庫

drop database databasename; //刪除選定的數(shù)據(jù)庫

exit    //退出數(shù)據(jù)庫的連接

create database test01;    //建立名為test的數(shù)據(jù)庫

show tables;        // 列出當前數(shù)據(jù)庫下的表

其他基本的增刪改查使用標準SQL即可


開放遠程登錄權(quán)限

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




向AI問一下細節(jié)

免責(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)容。

AI