linux mysql 安裝

操做系統html

Centos 7.2以上版本mysql

操做系統 centos 7.2以上版本

mysql 版本 mysql-5.7.23-el7-x86_64.tar.gzsql

1.1 安裝準備

一、  建立安裝文件存放目錄。數據庫

mkdir /usr/local/softwarecentos

二、 將安裝文件上傳至/usr/local/softwaresocket

三、 spa

1.2 MYSQL安裝

一、 使用root用戶分別登陸機器,分別按照安裝方式在三臺機器上進行安裝。操作系統

二、 建立MYSQL安裝目錄日誌

cd /usr/local/softwareserver

 

三、 進入安裝文件存放目錄。

cd /usr/local/software

四、 解壓MYSQL安裝包。

tar zxvf mysql-5.7.23-el7-x86_64.tar.gz

五、 將解壓文件拷貝至/usr/local/mysql目錄中。

cd mysql-5.7.23-el7-x86_64

cp -rf * /usr/local/mysql

六、 添加用戶和組

groupadd mysql

useradd -r -g mysql mysql

七、 手動建立MySql data和日誌目錄

mkdir /usr/local/mysql/data

mkdir /usr/local/mysql/log

八、 目錄權限設置

chown -R mysql:mysql /usr/local/mysql/data

chown -R mysql:mysql /usr/local/mysql/log

九、 配置my.cnf文件

vi /etc/my.cnf

#文件調整爲以下(server_id 配置項,三臺機器不可設置爲同樣,能夠根據ip地址最後一組數字進行設置):

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

server_id=128

port = 3306

user = mysql

socket = /tmp/mysql.sock

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

pid-file = /usr/local/mysql/data/mysql.pid

max_connections = 1000

max_connect_errors = 1000

table_open_cache = 1024

max_allowed_packet = 128M

open_files_limit = 65535

 

 

#####====================================[innodb]==============================

innodb_buffer_pool_size = 1024M

innodb_file_per_table = 1

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_purge_threads = 2

innodb_flush_log_at_trx_commit = 1

innodb_log_file_size = 512M

innodb_log_files_in_group = 2

innodb_log_buffer_size = 16M

innodb_max_dirty_pages_pct = 80

innodb_lock_wait_timeout = 30

innodb_data_file_path=ibdata1:1024M:autoextend

#####====================================[log]==============================

log_error = /usr/local/mysql/log/mysql-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /usr/local/mysql/log/mysql-slow.log

sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

十、 配置環境變量

vi /etc/profile

export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile

十一、 配置啓動文件

ln –s /usr/local/mysql/bin/mysql /usr/bin/mysql

十二、 系統默認啓動

touch /usr/lib/systemd/system/mysql.service

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE = 5000

#Restart=on-failure

#RestartPreventExitStatus=1

#PrivateTmp=false

 

1三、 初始化數據庫

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

   

使開機啓動文件生效

systemctl daemon-reload

啓動服務

systemctl start mysql

1四、 修改密碼和遠程訪問權限

查詢mysql 數據庫root用戶的密碼

more  /usr/local/mysql/log/mysql-error.log

密碼在mysql-error.log文件中的

 

登陸mysql

mysql -u root -p

輸入密碼後,會提示修改當前密碼,新密碼替換如下標紅處

SET PASSWORD = PASSWORD('root1234');

 

update mysql.user set authentication_string=password('root1234') where user='root';

 

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root1234';

 

FLUSH PRIVILEGES;

1五、 建立數據庫、用戶名和密碼

Create database uprofiledb;

Create user 'uprofile' @'%' IDENTIFIED BY 'uprofile';

GRANT ALL PRIVILEGES ON uprofiledb.* TO 'uprofile'@'%' IDENTIFIED BY 'uprofile';

FLUSH PRIVILEGES;

相關文章
相關標籤/搜索