centos7下安裝mysql5.7

1.安裝mysql依賴

yum -y install gcc cmake make gcc-c++ ncurses-devel openssl-devel bison ncurses chkconfig lsof  

2.下載mysql安裝包

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17.tar.gz  
tar -zxvf mysql-5.7.17.tar.gz   
cd mysql-5.7.17  

3.增加mysql用戶和用戶組

groupadd mysql   
useradd -g mysql mysql 

4.創建數據目錄


chown mysql.mysql -R /usr/local/mysql/   
mkdir -p /var/mysql/  
mkdir -p /var/mysql/data/  
chown mysql.mysql -R /var/mysql/

5.編譯安裝

cd /usr/local
/*mysql DDOWNLOAD_BOOST 會自動安裝在這個目錄上*/
mkdir boost_1_59_0
cmake \
     -DMYSQL_DATADIR=/var/mysql/data \
     -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
     -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
     -DDEFAULT_CHARSET=utf8 \
     -DWITH_EXTRA_CHARSETS:STRING=all \
     -DDEFAULT_COLLATION=utf8_general_ci \
     -DWITH_INNOBASE_STORAGE_engine=1 \
     -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
     -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
     -DMYSQL_TCP_PORT=3306 \
     -DENABLE_DOWNLOADS=1 \
     -DDOWNLOAD_BOOST=1 \
     -DWITH_BOOST=/usr/local/boost_1_59_0 \
     -DMYSQL_USER=mysql
/*編譯時間會比較漫長*/
make
make install

6.配置mysql文件

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf


# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /var/mysql/data
port = 3306
server_id = 1
socket = /var/mysql/mysql.socket

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket=/var/mysql/mysql.socket

7.增加mysql環境變量

vi /etc/profile
/*尾部增加*/
PATH=$PATH:/usr/local/mysql/bin
export PATH

/*保存成功後*/
source /etc/profile

8.初始化mysql數據

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/mysql/data 

9.啓動mysql

/etc/init.d/mysqld start
沒有報錯的話 恭喜你安裝成功了

10.進mysql修改密碼

/*使用該命令 再敲mysql 可以直接進mysql*/
mysqld_safe --skip-grant-tables &
mysql
use mysql
update user set authentication_string=password('123abc') where user='root';
/*然後退出安全模式重新登錄*/
mysql -uroot -p
123abc
/*這時候不管你怎麼操作都會提示*/
You must reset your password using ALTER USER statement before executing this statement.
/*再設置一次密碼*/
alter user 'root'@'localhost' identified by 'asdasd;657567';

11.增加遠程mysql用戶

Grant all on *.* to 'root'@'%' identified by 'user123' with grant option;
flush privileges;

mysql5.7你就安裝完啦 啊哈哈哈哈哈哈哈哈啊

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章