歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> CentOS6.5安裝mysql5.1.73,mysql5.1.73

CentOS6.5安裝mysql5.1.73,mysql5.1.73

日期:2017/3/3 18:18:12   编辑:學習Linux

CentOS6.5安裝mysql5.1.73,mysql5.1.73

CentOS6.5安裝mysql5.1.73,mysql5.1.73


思路:

1、查看有無安裝過mysql

rpm -qa|grep mysql

yum list installed mysql

2、查看有無安裝包

yum list mysql*

3、安裝mysql服務端

yum install mysql-server
yum install mysql-devel

4、啟動&&停止

  a、設置數據庫默認字符

    在mysql配置文件/etc/my.cnf中加入default-character-set=utf8

vim /etc/my.cnf

  b、設置開機自啟動

chkconfig mysqld on
chkconfig --list mysqld

  c、啟動mysql

service mysqld start

5、登錄

  a、創建root管理員

mysqladmin -u root password 123456

  b、忘記密碼

service mysqld stop
mysqld_safe --user=root --skip-grant-tables
mysql -u root
use mysql
update user set password=password("new_pass") where user="root";
flush privileges;  

6、遠程訪問

  a、修改localhost

    更改 "mysql" 數據庫裡的 "user" 表裡的 "host" 項,從"localhost"改成"%"

mysql>use mysql; 
mysql>update user set host = '%' where user = 'root'; 
mysql>select host, user from user;
mysql>FLUSH PRIVILEGES;

  b、指定授權

    1、使用myuser/mypassword從任何主機連接到mysql服務器:

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

    2、使用myuser/mypassword從ip為192.168.225.166的主機連接到mysql服務器:

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.166' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

    3、泛授權

mysql -h localhost -u root 
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; //賦予任何主機上以root身份訪問數據的權限 
mysql>FLUSH PRIVILEGES;

7、MySQL的幾個重要目錄

  a、數據庫目錄

/var/lib/mysql/

  b、配置文件

/usr/share /mysql(mysql.server命令及配置文件)

  c、相關命令

 /usr/bin(mysqladmin mysqldump等命令)

  d、啟動腳本

/etc/rc.d/init.d/(啟動腳本文件mysql的目錄)

8、卸載mysql

  a、查找以前是否裝有mysql

rpm -qa|grep -i mysql

  b、刪除mysql

1、yum remove mysql mysql-server mysql-libs compat-mysql51
2、rm -rf /var/lib/mysql
3、rm /etc/my.cnf

9、bug處理

  a、ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    解決方法:

    1、停止mysql服務器

service mysqld stop

    2、使用mysqld_safe命令在啟動mysql,更新root賬號的密碼

mysqld_safe --user=mysql --skip-grant-tables --skip-networking &:

    注:--skip-grant-tables:不啟動grant-tables(授權表),跳過權限控制。

      --skip-networking :跳過TCP/IP協議,只在本機訪問(從網上有些資料看,這個選項不是必須的。可以不用)

    執行上面命令後,此會話窗口會出現無反應的狀態,需要使用CTRL+C中斷會話

    3、設置密碼

mysql -u root mysql
mysql> update user set password=PASSWORD('12345')
    -> where user='root' and host='root' or host='localhost';
flush privileges

    4、啟動mysql服務

service mysqld start

http://xxxxxx/Linuxjc/1158883.html TechArticle

Copyright © Linux教程網 All Rights Reserved