首頁  >  問答  >  主體

yum - linux7.0安装mysql的问题

安装mysql

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

启动mysql
service mysqld restart
设置密码

[root@YFPUNzLr ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

可我没设置密码啊,网上找了几个方式都没用。

ringa_leeringa_lee2743 天前763

全部回覆(6)我來回復

  • 迷茫

    迷茫2017-04-17 16:35:55

    網上找到的有效答案:
    密碼在/var/log/mysqld.log這個文件裡
    可以用grep 'temporary password' /var/log/mysqld.log來查詢,也可以自己在文件裡找。

    [root@YFPUNzLr ~]# grep 'temporary password' /var/log/mysqld.log
    2017-02-15T14:31:05.449058Z 1 [Note] A temporary password is generated for root@localhost: 3NeI3PuNwa%j
    [root@YFPUNzLr ~]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10
    Server version: 5.7.17
    
    Copyright (c) 2000, 2016, 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> 

    回覆
    0
  • 巴扎黑

    巴扎黑2017-04-17 16:35:55

    不知道你的MySQL版本和系統版本是多少。多少。如果是5.7的話,可能在日誌檔裡面有記錄。
    如果日誌檔裡面沒有,可以重設密碼的,不需要重新安裝的。
    MySQL 5.7.6 以及最新版本:

    vim /etc/my.cnf
    # 添加下面的字段
    skip-grant-tables 
    mysql> update user set mysql>authentication_string=PASSWORD('123456') where User='root';
    mysql>flush privileges;  
    

    以前的版本,

    vim /etc/my.cnf
    # 添加下面的字段
    skip-grant-tables 
    mysql> use mysql;
    mysql> update user set password=PASSWORD("password") where User='root';  
    mysql> flush privileges;  

    回覆
    0
  • 迷茫

    迷茫2017-04-17 16:35:55

    看一下錯誤日誌,應該有個password的字段,後面跟著一串奇怪的東西就是密碼
    如果沒有就重置密碼吧

    回覆
    0
  • 阿神

    阿神2017-04-17 16:35:55

    薛丁格的密碼…

    你應該是安裝時設定密碼了 如果忘了的話就卸載重新安吧 如果還是不行去看一下mysql日誌 看看有什麼報錯沒 再不行就百度mysql忘記密碼看怎麼強制修改

    回覆
    0
  • 巴扎黑

    巴扎黑2017-04-17 16:35:55

    預設密碼有可能保存在檔案~/.mysql_secret中。

    回覆
    0
  • 怪我咯

    怪我咯2017-04-17 16:35:55

    mysql預設root密碼是空的。

    登入用
    mysql -u root -p

    另外你可以執行以下 mysql_secure_insatllation 設定密碼

    回覆
    0
  • 取消回覆