5.2.1通過service mysqld start啟動(dòng)服務(wù),查看mysql進(jìn)程信息,獲取mysqld_safe的安裝目錄
[root@localhost ~]# ps -ef | grep -i mysqlroot 1151 1 0 15:00 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysqlmysql 1350 1151 0 15:00 ? 00:00:02 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sockroot 1487 1473 0 15:17 pts/0 00:00:00 grep -i mysql
可以看到mysqld_safe的安裝位置(上面標(biāo)紅色部分):/usr/bin/5.2.2通過service mysqld stop 停止服務(wù)5.2.3以安全方式啟動(dòng)mysql:#/usr/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &5.2.4稍等5秒鐘,然后執(zhí)行以下語句:#/usr/bin/mysql -u root mysql注意:mysql與mysql_safe目錄一樣,都是:/usr/bin/下,這個(gè)是通過“ps -ef | grep -i mysql”命令得到的。出現(xiàn)“mysql>”提示符后輸入:mysql> update user set authentication_string = password('123456') where User = 'root';回車后執(zhí)行(刷新MySQL系統(tǒng)權(quán)限相關(guān)的表):mysql> flush privileges;再執(zhí)行exit退出:mysql> exit;
注意:authentication_string在之前的mysql版本此處是password退出后,使用以下命令登陸mysql,試試是否成功:#mysql -u root -p 按提示輸入密碼:123456但是執(zhí)行查看數(shù)據(jù)庫命令報(bào)錯(cuò):mysql> show databases;ERROR 1820 (HY000): You must SET PASSWORD before executing this statement解決辦法:mysql> SET PASSWORD=PASSWORD('root');Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
6.開啟3306端口#vi /etc/sysconfig/iptables在iptables中添加如下一行-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT重啟服務(wù)service iptables restart7.設(shè)置開機(jī)啟動(dòng)查看mysql服務(wù)是不是開機(jī)自動(dòng)啟動(dòng) #chkconfig --list | grep mysqld 命令來將其設(shè)置成開機(jī)啟動(dòng) #chkconfig mysqld on 8.查看mysql是否有啟動(dòng) #ps -A|grep mysql新聞熱點(diǎn)
疑難解答
圖片精選