mysql-5.7.23-linux-glibc2.12-x86_64安裝
安裝環境Centos7_X64
3、切換目錄(自定義)
#> cd /usr/local
解壓(mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz已經複製到/usr/local下)
#> tar zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
5、創建軟鏈接
#> ln -s mysql-5.7.23-linux-glibc2.12-x86_64 mysql
7、進入mysql目錄
#> cd mysql
8、創建配置文件my.cnf,複製到/etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
port=3306
basedir=/home/zhuge/mysql/mysql
datadir=/home/zhuge/mysql/mysql/data
max_connections=200
character-set-server=utf8
#default-storge-engine=INNODB
*********重要*********
初始化MySQL命令
mysqld --initialize
提示信息:
------------
2019-02-19T17:18:04.522416Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more deta ils).
2019-02-19T17:18:04.883839Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-02-19T17:18:05.280408Z 0 [Warning] InnoDB: Creating foreign key constraint system table s.
2019-02-19T17:18:05.499917Z 0 [Warning] No existing UUID has been found, so we assume that t his is the first time that this server has been started. Generating a new UUID: 51cbcad3-346 a-11e9-bd80-000c29e5966e.
2019-02-19T17:18:05.502372Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gti d_executed' cannot be opened.
2019-02-19T17:18:05.505574Z 1 [Note] A temporary password is generated for root@localhost: I U4C>6,=pPTR (最後這個就是自動生成的密碼)
------------
*********重要*********
9、添加mysql的環境變量,修改 ~/.bashrc 或者 /etc/profile
export MYSQL_HOME=/home/zhuge/mysql/mysql
export PATH=$MYSQL_HOME/bin:$MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH
9 複製啓動腳本 cp support-files/mysql.server /etc/init.d/mysqld
10、修改sudo vi /etc/init.d/mysqld文件
設置basedir=${你的mysql目錄} datadir=${你的mysql目錄}/data
設置mysqld_safe --user=zhuge
11、service mysqld start 啓動mysql服務
12 登錄mysql
[root@localhost mysql]# mysql -S /opt/mysql/mysql.sock -uroot -p
Enter password:輸入你的密碼(IU4C>6,=pPTR)
13 修改密碼
step 1: SET PASSWORD = PASSWORD('root');
step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
step 3: flush privileges;
重啓登錄即可
如果出現如下異常
[root@localhost ~]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
則在my.cnf中添加如下配置
[mysql]
socket=/opt/mysql/mysql.sock # 指定sock地址
-----------
這樣客戶端在登錄時就會去指定的目錄查找mysqld.socket文件,注意client的socket要和mysqld是一樣的,因爲客戶端和服務端通信靠的就是這個文件,肯定要一致。
授權遠程訪問:
SELECT PASSWORD('root'); ##獲取加密密碼 ,放在授權語句PASSWORD後
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.25.%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION; #授權語句
FLUSH PRIVILEGES; #刷新命令
##########其他##########
忘記密碼的解決方案
9、使用命令bin/mysqld_safe --skip-grant-tables 跳過密碼驗證啓動服務,直接使用 mysql -uroot 登錄mysql,使用下面命令修改密碼
update mysql.user set authentication_string=password(“root”), password_expired=‘N’ where user=‘root’;
刷新
flush privileges;
10、再次bin/mysqld_safe --user=zhuge 正常啓動,使用命令登錄mysql -uroot -p,提示輸入設置的密碼即可正常登錄
11、後臺啓動 (暫時不用)
bin/mysqld 1>/dev/null 2>&1 &
11、複製配置文件
#> cp support-files/my-medium.cnf /etc/my.cnf
#> cp support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld #修改這個文件的內容
may be overwritten at next upgrade.
$bindir/mysqld_safe --user=root … # --user=root是新加上的
12、啓動數據庫
#> /etc/init.d/mysqld start
13、查看是否有3306端口啓動
#> netstat -nat
14、設置密碼
#> mysqladmin -u root password ‘root’
授權命令(所有遠程都可訪問)
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;
flush PRIVILEGES; #刷新授權