1、yum安裝mysql 安裝結果 2、設置開機啟動 3、MySQL服務 3.1、MySQL服務開啟 3.2、MySQL服務關閉 3.1、MySQL服務重啟 4、MySQL密碼 4.1、設置密碼 4.2、密碼忘記 4.2.1、修改/etc/my.cnf 4.2.2、重啟MySql 4.2.3、修改密 ...
1、yum安裝mysql
[root@localhost ~]# yum -y install mysql-server
安裝結果
Installed:
mysql-server.x86_64 0:5.1.73-7.el6
Dependency Installed:
mysql.x86_64 0:5.1.73-7.el6 perl-DBD-MySQL.x86_64 0:4.013-3.el6
Complete!
2、設置開機啟動
[root@localhost ~]# chkconfig mysqld on
3、MySQL服務
3.1、MySQL服務開啟
[root@localhost ~]# service mysqld start
3.2、MySQL服務關閉
[root@localhost ~]# service mysqld stop
3.1、MySQL服務重啟
[root@localhost ~]# service mysqld restart
4、MySQL密碼
4.1、設置密碼
[root@stonex ~]# mysql -u root
mysql> set password for root@localhost=password('root');
mysql> exit
4.2、密碼忘記
4.2.1、修改/etc/my.cnf
1 [mysqld] 2 datadir=/var/lib/mysql 3 socket=/var/lib/mysql/mysql.sock 4 user=mysql 5 #最重要的下麵這一行代碼 6 skip-grant-tables 7 # Disabling symbolic-links is recommended to prevent assorted security risks 8 symbolic-links=0 9 10 [mysqld_safe] 11 log-error=/var/log/mysqld.log 12 pid-file=/var/run/mysqld/mysqld.pid
4.2.2、重啟MySql
[root@localhost ~]# service mysqld restart
4.2.3、修改密碼
1 [root@localhost ~]# mysql -u root 2 mysql> use mysql; 3 mysql> set password for root@localhost=password('root'); 4 mysql> flush privileges; 5 mysql> exit; 6 [root@localhost ~]# service mysqld restart
4.2.4、修改/etc/my.cnf
[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
4.3、MySQL登陸
[root@localhost ~]# mysql -u root -p
4.4、MySQL常用命令
1 show databases; //查看系統已存在的資料庫 2 use databasesname; //選擇需要使用的資料庫 3 drop database databasename; //刪除選定的資料庫 4 exit //退出資料庫的連接 5 create database test01; //建立名為test的資料庫 6 show tables; // 列出當前資料庫下的表 7 其他基本的增刪改查使用標準SQL即可
4.5、MySQL開放遠程登陸許可權
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;