關於Linux下MySQL密碼得相關問題
首先進行yum安裝MySQL
yum install mysql
/*然後執行一個 mysql -v
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
這個時候回報一個mysql-server錯誤*/
yum install mysql-server
/*這個時候回報一個依賴錯誤*/
Error downloading packages:
mysql-community-client-5.7.26-1.el6.x86_64: [Errno 256] No more mirrors to try.
mysql-community-common-5.7.26-1.el6.x86_64: [Errno 256] No more mirrors to try.
mysql-community-libs-5.7.26-1.el6.x86_64: [Errno 256] No more mirrors to try.
接下來,我們需要去清楚緩存
yum clean cache
yum makecache
/*清楚完畢之後,再去執行*/
yum install mysql-server
/*這個時候應該就差不多可以了*/
安裝成功之後我們啓動MySQL
mysql-server成功了之後,使用centos7的啓動命令,如果您是CentOS6,建議先使用一下yum -y update
systemctl start mysql-server 開啓
systemctl stopmysql-server 停止
systemctl restart mysql-server 重啓
啓動成功之後,我們進入mysql,進行操作
mysql -uroot -p
Enter password:
/*第一次進入咱們不知道密碼,咱也不敢問啊這個時候就會出現這個錯誤
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) :沒有輸入直接回車
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) :瞎**亂輸入,沒有進去
*/
/*首次進入mysql 先在Linux中找一下mysql的配置*/
find / -name my.cnf
/*如下圖,我們使用vim進入之後,在mysqld下面加一段那個代碼,可以免密進入數據庫*/
skip-grant-tables
mysql -uroot -p /*回車回車,進入數據庫,接下來我們去修改密碼*/
show databases; /*看一下數據庫,多練習練習基礎命令*/
use mysql; /*我們去修改密碼啦*/
#這個地方我們要知道自己的數據庫是什麼版本,因爲版本不同,使用的命令也不同
#mysql5.7:
mysql> update mysql.user set authentication_string=password('123456') where user='root'; #修改密碼成功
#mysql5.6:
mysql> update user set password=password(“123456”) where user=”root”; #修改密碼成功
#看版本找不同,你值得擁有,修改完看一下是不是返回的 ok
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; #刷新緩存,立即生效
#然後退出mysql。找到my.cnf,把那個代碼去掉。