您好,登錄后才能下訂單哦!
[root@CentOS61 ~]# yum install cmake nucrses-devel –y //安裝編譯環境及終端操作的開發包
……
Installed:
cmake.x86_64 0:2.8.12.2-4.el6
Dependency Installed:
libarchive.x86_64 0:2.8.3-7.el6_8
Complete!
[root@CentOS61 ~]# wget http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz
。。。。。。
100%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>] 32,167,628 24.0K/s in 2.2s
2017-04-12 22:23:19 (24.0 KB/s) - “mysql-5.6.35.tar.gz” saved [32167628/32167628]
注意:如果命令下載較慢的話,可以使用windows下載后再傳到linux上
解壓
[root@CentOS61 ~]# tar -xf mysql-5.6.35.tar.gz -C /usr/local/src/ //-C 指定解壓目錄
[root@CentOS61 ~]# ls /usr/local/src/
mysql-5.6.35
檢查mysql用戶是否存在
[root@CentOS61 ~]# grep mysql /etc/passwd
創建用戶
[root@CentOS61 ~]# useradd -u 8001 -s /sbin/nologin mysql
創建數據庫目錄
[root@CentOS61 ~]# mkdir /data
[root@CentOS61 ~]# cd /usr/local/src/mysql-5.6.35/
[root@CentOS61 mysql-5.6.35]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data -DMYSQL_USER=mysql
開始編譯并安裝
[root@CentOS61 mysql-5.6.35]# make -j 4 && make install
結束后使用$?查看是否成功
[root@CentOS61 mysql-5.6.35]# echo $?
0
[root@CentOS61 mysql-5.6.35]# chown -R mysql:mysql /usr/local/mysql
[root@CentOS61 mysql-5.6.35]# chown -R mysql:mysql /data
[root@CentOS61 mysql-5.6.35]# chmod 1777 /tmp/
覆蓋已有的配置文件
[root@CentOS61 mysql-5.6.35]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@CentOS61 mysql-5.6.35]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
[root@CentOS61 mysql-5.6.35]# source !$ //生效文件
source /etc/profile
[root@CentOS61 mysql-5.6.35]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld //復制啟動腳本并重命名為mysqld
[root@CentOS61 mysql-5.6.35]# chmod +x !$
chmod +x /etc/init.d/mysqld //賦予腳本執行權限
[root@CentOS61 ~]# vim /etc/init.d/mysqld
修改
46 basedir=
47 datadir=
為
46 basedir=/usr/local/mysql
47 datadir=/data
[root@CentOS61 ~]# chkconfig mysqld on //設置開機自啟動
[root@CentOS61 ~]# chmod +x /usr/local/mysql/scripts/mysql_install_db //給目錄添加執行權限
[root@CentOS61 ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/ --user=mysql //指定配置文件、指定目錄、指定用戶(需要一點時間)
[root@CentOS61 ~]# service mysqld start //啟動服務
Starting MySQL.Logging to '/data/CentOS61.err'.
...................................................................................................................... SUCCESS!
注意:需要幾分鐘,可能是數據庫版本問題
[root@CentOS61 ~]# service mysqld status //查看服務狀態
SUCCESS! MySQL running (16856)
[root@CentOS61 ~]# mysql_secure_installation
……
Enter current password for root (enter for none): //要求輸入密碼,沒有密碼直接回車
……
Set root password? [Y/n] Y //提示設置root密碼
New password: //輸入要設置的密碼123456(密文顯示)
Re-enter new password: //重復確認密碼
……
Remove anonymous users? [Y/n] y //是否刪除匿名用戶(匿名用戶可登錄服務器,需要刪除)
......
Disallow root login remotely? [Y/n] Y //禁止root用戶遠程登錄
……
Remove test database and access to it? [Y/n] Y //刪除測試數據庫(創建好數據庫,測試數據庫就沒用了)
……
Reload privilege tables now? [Y/n] Y //刷新數據庫列表
[root@CentOS61 ~]# mysql -u root -p123456 //登錄數據庫
mysql> show engines; //查看默認引擎
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
安裝MySQL Complete
環境:CentOS6.7 Mysql5.6.35版本 Mysql數據庫忘記root密碼如何修改
登錄Mysql數據庫忘記密碼
[root@CentOS61 ~]# mysql –V //查看mysql版本
mysql Ver 14.14 Distrib 5.6.35, for Linux (x86_64) using EditLine wrapper
[root@CentOS61 ~]# mysql -uroot –p //登錄數據庫
Enter password: //忘記密碼
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@CentOS61 ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@CentOS61 ~]# mysqld_safe --skip-grant-tables
170413 01:51:11 mysqld_safe Logging to '/data/CentOS61.err'.
170413 01:51:11 mysqld_safe Starting mysqld daemon with databases from /data
Ctrl+z 重新設置好root密碼后終止
[1]+ Stopped mysqld_safe --skip-grant-tables
新開一個窗口登錄數據庫,可以跳過密碼認證
[root@CentOS61 ~]# mysql //直接進入數據庫
mysql> use mysql //進入mysql數據庫
mysql> update user set password=password("1234567") where user="root"; //修改root密碼
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges; //刷新權限
Query OK, 0 rows affected (0.01 sec)
mysql> exit //退出數據庫
[root@CentOS61 ~]# pkill mysql //停止mysql數據庫
[root@CentOS61 ~]# service mysqld start
Starting MySQL.. SUCCESS!
[root@CentOS61 ~]# mysql -uroot -p1234567 //使用新的密碼重新登錄數據庫
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。