centos7 + mysql5.7 tar包解壓安裝
阿新 • • 發佈:2018-11-09
MySQL官網下載地址:https://dev.mysql.com/downloads/mysql/
~]# rpm -qa|-libs-.-~]# rpm -e --nodeps mariadb-libs-.-~]# /etc/: cannot remove ?etc/my.cnf? No such ~]# rpm -qa | ~~]# /etc/group | ~]# /etc/ | ~~]# useradd -~]# /usr/local空間不足,所以我安裝到/ -zxvf mysql-.-linux-glibc2.-x86_64. mysql-.-linux-glibc2.-x86_64/ -R mysql mysql57/ -R mysql mysql57/ [[email protected] var]# cd mysql57/ [[email protected] mysql57]# mkdir data
在etc下新建配置檔案my.cnf,並在該檔案內新增以下配置
[mysql]
# 設定mysql客戶端預設字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#設定3306埠
port = 3306
# 設定mysql的安裝目錄
basedir=/var/mysql57
# 設定mysql資料庫的資料的存放目錄
datadir=/var/mysql57/data
# 允許最大連線數
max_connections=200
# 服務端使用的字符集預設為8位元編碼的latin1字符集
character-set-server=utf8
# 建立新表時將使用的預設儲存引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
安裝和初始化
[[email protected] mysql57]# bin/mysql_install_db --user=mysql --basedir=/var/mysql57/ --datadir=/var/mysql57/data/2017-04-17 17:40:02 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2017-04-17 17:40:05 [WARNING] The bootstrap log isn't empty:2017-04-17 17:40:05 [WARNING] 2017-04-17T09:40:02.728710Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2017-04-17T09:40:02.729161Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2017-04-17T09:40:02.729167Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)
[[email protected] mysql57]# cp ./support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql57]# chown 777 /etc/my.cnf [[email protected] mysql57]# chmod +x /etc/init.d/mysqld
[[email protected] mysql57]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! #設定開機啟動 [[email protected] mysql57]# chkconfig --level 35 mysqld on [[email protected] mysql57]# chkconfig --list mysqld [[email protected] mysql57]# chmod +x /etc/rc.d/init.d/mysqld [[email protected] mysql57]# chkconfig --add mysqld [[email protected] mysql57]# chkconfig --list mysqld [[email protected] mysql57]# service mysqld status SUCCESS! MySQL running (4475)
etc/profile/
export PATH=$PATH:/var/mysql57/bin [[email protected] mysql57]# source /etc/profile
獲得初始密碼
[[email protected] bin]# cat /root/.mysql_secret # Password set for user '[email protected]' at 2017-04-17 17:40:02 _pB*3VZl5T<6
修改密碼
[[email protected] bin]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5Server version: 5.7.18Copyright (c) 2000, 2017, 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> set PASSWORD = PASSWORD('111111'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
新增遠端訪問許可權
mysql>-> update user set host= where user= row affected ( Changed: Warnings: > +-----------+-----------+ | host | user | +-----------+-----------+ | % | root | | localhost | mysql.sys | +-----------+-----------+ rows set ( sec) create user 'xxx'@'%' identified by '123'; 這裡 @‘%’ 表示在任何主機都可以登入
重啟生效
/bin/systemctl restart mysql.service [[email protected] bin]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
為了在任何目錄下可以登入mysql
ln -s /var/mysql57/bin/mysql /usr/bin/mysql