222 lines
4.5 KiB
Markdown
222 lines
4.5 KiB
Markdown
|
### 安装$Mysql$ $5.7$
|
|||
|
|
|||
|
```shell
|
|||
|
yum install lrzsz -y
|
|||
|
mkdir /usr/local -p
|
|||
|
cd /usr/local
|
|||
|
rz -be 选择 mysql-5.7.42-el7-x86_64.tar.gz
|
|||
|
tar -zxf mysql-5.7.42-el7-x86_64.tar.gz
|
|||
|
mv mysql-5.7.42-el7-x86_64 mysql
|
|||
|
rm -rf mysql-5.7.42-el7-x86_64.tar.gz
|
|||
|
|
|||
|
vi /etc/profile
|
|||
|
#添加如下内容
|
|||
|
export PATH=/usr/local/mysql/bin:$PATH
|
|||
|
#然后source生效
|
|||
|
source /etc/profile
|
|||
|
|
|||
|
#添加用户并授权相关
|
|||
|
useradd mysql
|
|||
|
id mysql
|
|||
|
mkdir /data/mysql -p
|
|||
|
chown -R mysql:mysql /usr/local/mysql/*
|
|||
|
chown -R mysql:mysql /data/*
|
|||
|
|
|||
|
其中:
|
|||
|
/usr/local/mysql/是MySQL软件所在目录。
|
|||
|
/data/mysql是将来存放MySQL数据的目录。
|
|||
|
|
|||
|
#安装依赖包
|
|||
|
yum install libaio -y
|
|||
|
#初始化数据库
|
|||
|
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
|
|||
|
|
|||
|
|
|||
|
#配置文件
|
|||
|
|
|||
|
vi /etc/my.cnf
|
|||
|
|
|||
|
[mysqld]
|
|||
|
basedir = /usr/local/mysql
|
|||
|
datadir = /data/mysql
|
|||
|
skip-external-locking
|
|||
|
skip-name-resolve
|
|||
|
back_log = 100
|
|||
|
max_connections = 2048
|
|||
|
max_connect_errors = 30
|
|||
|
table_open_cache = 2048
|
|||
|
open_files_limit = 16384
|
|||
|
max_allowed_packet = 16M
|
|||
|
read_buffer_size = 8M
|
|||
|
read_rnd_buffer_size = 32M
|
|||
|
sort_buffer_size = 2M
|
|||
|
join_buffer_size = 2M
|
|||
|
thread_cache_size = 16
|
|||
|
query_cache_size = 128M
|
|||
|
query_cache_limit = 4M
|
|||
|
slow_query_log = 1
|
|||
|
long_query_time = 2
|
|||
|
lower_case_table_names = 1
|
|||
|
innodb_file_per_table = 1
|
|||
|
max_allowed_packet = 64M
|
|||
|
server-id = 1
|
|||
|
log-bin = mysql-bin
|
|||
|
expire_logs_days = 7
|
|||
|
binlog_format = ROW
|
|||
|
|
|||
|
innodb_data_file_path = ibdata1:10M:autoextend
|
|||
|
innodb_buffer_pool_size = 2G
|
|||
|
innodb_write_io_threads = 8
|
|||
|
innodb_read_io_threads = 8
|
|||
|
innodb_flush_log_at_trx_commit = 2
|
|||
|
innodb_log_buffer_size = 16M
|
|||
|
innodb_log_file_size = 170M
|
|||
|
innodb_lock_wait_timeout = 60
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#### 管理MySQL_etc/init.d
|
|||
|
|
|||
|
```shell
|
|||
|
mkdir /etc/init.d -p
|
|||
|
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#### 重定向文件
|
|||
|
|
|||
|
```
|
|||
|
ln -s /usr/lib64/libncurses.so.6.2 /usr/lib64/libncurses.so.5
|
|||
|
ln -s /usr/lib64/libtinfo.so.6.2 /usr/lib64/libtinfo.so.5
|
|||
|
|
|||
|
#启动、重启命令
|
|||
|
service mysqld start
|
|||
|
service mysqld restart
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#### 重置密码
|
|||
|
|
|||
|
```
|
|||
|
/etc/init.d/mysqld stop
|
|||
|
|
|||
|
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
|
|||
|
mysql
|
|||
|
update mysql.user set authentication_string=PASSWORD("DsideaL147258369") where user='root' and host='localhost';
|
|||
|
|
|||
|
flush privileges;
|
|||
|
|
|||
|
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'DsideaL147258369' WITH GRANT OPTION;
|
|||
|
|
|||
|
flush privileges;
|
|||
|
exit
|
|||
|
|
|||
|
/etc/init.d/mysqld restart
|
|||
|
mysql -uroot -pDsideaL147258369
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
现在用Navicat Prenium就可以远程访问到数据库了。
|
|||
|
|
|||
|
```
|
|||
|
YLT项目中使用的用户名:ycharge,密码:ycharge 需要创建
|
|||
|
CREATE USER 'ycharge'@'%' IDENTIFIED BY 'ycharge';
|
|||
|
GRANT all privileges ON yltcharge.* TO 'ycharge'@'%';
|
|||
|
FLUSH PRIVILEGES;
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#### 创建使用账号
|
|||
|
|
|||
|
```sql
|
|||
|
GRANT ALL PRIVILEGES ON *.* TO ycharge@"%" IDENTIFIED BY "ycharge";
|
|||
|
flush privileges;
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
$/etc/my.cnf$
|
|||
|
|
|||
|
```
|
|||
|
[mysqld]
|
|||
|
user=mysql
|
|||
|
basedir=/usr/local/mysql
|
|||
|
datadir=/usr/local/db/mysql_bkdata
|
|||
|
log-bin=/usr/local/mysql/binlog
|
|||
|
binlog_format=row
|
|||
|
server_id=1
|
|||
|
port=22066
|
|||
|
socket=/tmp/mysql.sock
|
|||
|
|
|||
|
|
|||
|
default-time-zone='Asia/Shanghai'
|
|||
|
|
|||
|
lower_case_table_names=1
|
|||
|
max_connections = 2048
|
|||
|
max_connect_errors = 30
|
|||
|
table_open_cache = 2048
|
|||
|
open_files_limit = 16384
|
|||
|
max_allowed_packet = 16M
|
|||
|
read_buffer_size = 8M
|
|||
|
read_rnd_buffer_size = 32M
|
|||
|
sort_buffer_size = 2M
|
|||
|
join_buffer_size = 2M
|
|||
|
thread_cache_size = 16
|
|||
|
query_cache_size = 128M
|
|||
|
server_id=1
|
|||
|
|
|||
|
port=22066
|
|||
|
socket=/tmp/mysql.sock
|
|||
|
|
|||
|
|
|||
|
default-time-zone='Asia/Shanghai'
|
|||
|
|
|||
|
lower_case_table_names=1
|
|||
|
max_connections = 2048
|
|||
|
max_connect_errors = 30
|
|||
|
table_open_cache = 2048
|
|||
|
open_files_limit = 16384
|
|||
|
max_allowed_packet = 16M
|
|||
|
read_buffer_size = 8M
|
|||
|
read_rnd_buffer_size = 32M
|
|||
|
sort_buffer_size = 2M
|
|||
|
join_buffer_size = 2M
|
|||
|
thread_cache_size = 16
|
|||
|
query_cache_size = 128M
|
|||
|
query_cache_limit = 4M
|
|||
|
slow_query_log = 1
|
|||
|
long_query_time = 2
|
|||
|
innodb_file_per_table = 1
|
|||
|
max_allowed_packet = 64M
|
|||
|
|
|||
|
innodb_data_file_path = ibdata1:10M:autoextend
|
|||
|
innodb_buffer_pool_size = 2G
|
|||
|
innodb_write_io_threads = 8
|
|||
|
innodb_read_io_threads = 8
|
|||
|
innodb_flush_log_at_trx_commit = 2
|
|||
|
innodb_log_buffer_size = 16M
|
|||
|
innodb_log_file_size = 170M
|
|||
|
innodb_lock_wait_timeout = 60
|
|||
|
|
|||
|
#sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
|||
|
|
|||
|
sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
|||
|
|
|||
|
[mysql]
|
|||
|
socket=/tmp/mysql.sock
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
### 挂载磁盘
|
|||
|
|
|||
|
```
|
|||
|
mount /dev/sdb1 /usr/local/db
|
|||
|
```
|
|||
|
|