linux安裝mysql

基礎(chǔ)概念

dql -select
dml -insert update delete
ddl -create table create view
dcl -grant

安裝步驟(centos7)

  • sudo yum install mysql mysql-server
    sudo yum -y install mysql-server(centos6)
  • sudo vim /etc/my.cnf
  • 修改文件增加,default-character-set = utf8
  • 啟動(dòng)mysql
    systemctl start mysqld

centos6啟動(dòng)
service mysqld start

  • 設(shè)置隨系統(tǒng)啟動(dòng)
    systemctl enable mysqld
    systemctl daemon-reload

centos6中設(shè)置隨系統(tǒng)啟動(dòng)
sudo chkconfig mysqld on
sudo chkconfig --list mysqld

  • 登錄mysql
    mysql -u root

  • 查看用戶
    select user,host from mysql.user;

  • 刪除匿名用戶
    delete from mysql.user where user='';

  • 刷新權(quán)限
    flush privileges;

  • 防火墻開(kāi)放3306端口
    sudo vim /etc/sysconfig/iptables
    -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

  • 重啟防火墻
    sudo systemctl restart iptables.service
    sudo service iptables restart(centos6)

  • 新建用戶(7會(huì)報(bào)錯(cuò),原因未知)
    insert into mysql.user(Host,User,Password) values("localhost","qinxianyun",password("qinxianyun"));

  • 創(chuàng)建數(shù)據(jù)庫(kù)(是數(shù)字鍵1左邊的小點(diǎn),用單引號(hào)會(huì)報(bào)錯(cuò)) create databasemmall` default character set utf8 collate utf8_general_ci;

  • 查看權(quán)限
    select * from mysql.user \G

  • 授權(quán)
    grant all privileges on mmall.* to qinxianyun@'%' identified by 'qinxianyun' with grant option;

  • 為root用戶設(shè)置密碼
    set password for root@localhost=password('admin123');
    set password for root@127.0.0.1=password('admin123');
    select user,host,password from mysql.user;
    set password for root@localhost.localdomain=password('admin123');

  • 授權(quán)遠(yuǎn)程訪問(wèn)(能訪問(wèn)可以不設(shè)置)
    use mysql;
    grant all privileges on . to root@'%' identified by "root";
    FLUSH RIVILEGES;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容