1. 程式人生 > >7、mysql的配置和安裝

7、mysql的配置和安裝

tail 創建 san ext 註意 重新 ica data value

  1. linux環境下mysql的安裝
    1. sudo yum install mysql-server
  2. 修改配置文件
    1. vim /etc/my.cnf
      1. 添加default-character-set = utf8
  3. 設置mysql隨系統自動啟動
    1. 檢查設置是否正確
      1. sudo chkconfig --list mysqld
        1. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
        2. 2-5都是啟動則ok
  4. 啟動mysql
    1. sudo service mysqld start
      1. 如果出現錯誤 MySQL Daemon failed to start. 請參考
        1. http://blog.csdn.net/u012286517/article/details/50436740

    2. 刪除匿名用戶
      1. select user,host from mysql.user;
        1. +------+--------------------+
        2. | user | host |
        3. +------+--------------------+
        4. | root | 127.0.0.1 |
        5. | | localhost |
        6. | root | localhost |
        7. | | vm\_24\_26\_centos |
        8. | root | vm\_24\_26\_centos |
        9. +------+--------------------+
      2. delete from mysql.user where user=‘‘;
    3. 刷新一下權限
      1. flush privileges;
    4. 在防火墻下面開放3306端口,開放給外網
      1. sudo vim /etc/sysconfig/iptables
        1. #mysql port
        2. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
      2. 重啟防火墻
        1. service iptables restart
    5. 重新登錄mysql
      1. mysql -u root
    6. 創建一個非root權限的賬戶,避免使用root
      1. insert into mysql.user(Host,User,Password)values("localhost","mmall",password("mmall"
        ));
      2. 檢查插入是否正確
        1. select user,host from mysql.user;
          1. +-------+--------------------+
          2. | user | host |
          3. +-------+--------------------+
          4. | root | 127.0.0.1 |
          5. | mmall | localhost |
          6. | root | localhost |
          7. | root | vm\_24\_26\_centos |
          8. +-------+--------------------+
    7. 創建一個數據庫
      1. create database `mmall` default character set utf8 collate utf8_general_ci;
    8. 查看權限
      1. select * from mysql.user \G
    9. 賦予權限
      1. 切換數據庫 use mmall;
      2. grant all privileges on mmall.* to mmall@‘%‘ identified by ‘mmall‘ with grant option;
        1. 註意,此語句可能有錯誤,導致執行下面的權限查詢的時候出現授權不起作用的現象,可以改為下面的授權語句。
          1. grant all privileges on *.* to mmall@‘%‘ identified by ‘mmall‘ with grant option;
        2. 請參看
          1. https://bbs.csdn.net/topics/330154879
      3. 可以更細化權限為
        1. grant select,delete,create on mmall.* to mmall@‘%‘ identified by ‘mmall‘ with grant option;
    10. 重新查看全新
        1. select * from mysql.user \G


    11. 修改root賬號的密碼
      1. set password for root@localhost=password(‘root‘);
      2. set password for [email protected]=password(‘root‘);
      3. select user,host,password from mysql.user;
    12. 退出重新登錄
      1. 使用密碼登錄,否則沒有權限
  5. win下安裝mysql


來自為知筆記(Wiz)

7、mysql的配置和安裝