系统 CentOS 7:

http://mirrors.aliyun.com/centos/7/isos/x86_64/

MySQL 安装

安装依赖包

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

安装 MySQL ,编译安装需要 boost 库,在官网下载含 boost 的源码包

https://dev.mysql.com/downloads/mysql/5.7.html

curl -O https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.30.tar.gz

添加用户

useradd -s /sbin/nologin mysql

建立所需目录并更改所有者为 mysql

mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql

解压,编译安装

tar -zxvf mysql-boost-5.7.30.tar.gz
cd mysql-5.7.30/
cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
make && make install

安装后得 /usr/local/mysql 目录

编辑配置文件 vim /etc/my.cnf 

[client]
port        = 3306
socket      = /tmp/mysql.sock

[mysqld]
port        = 3306
socket      = /tmp/mysql.sock
user = mysql


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

log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log


skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1024M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
performance_schema_max_table_instances = 1000

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log_bin=mysql-bin
binlog_format=mixed
server_id   = 232
expire_logs_days = 10
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M

安装目录和数据目录修改用户组

注:/data/mysql/data 目录要为空

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

初始化 MySQL

/data/mysql/data 这个目录须为空,指定的 basedir 和 datadir 目录须和/etc/my.cnf 配置的目录一致

cd /usr/local/mysql/bin
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data

设置服务文件

cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysqld

启动

service mysqld start

连接测试(密码空)

cd /usr/local/mysql/bin
./mysql -hlocalhost -uroot -p

修改环境变量

vim /etc/profile

最后增加一行

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

保存退出,刷新权限,设置服务

source /etc/profile
systemctl enable mysqld

centos7 源码编译安装 mysql5.7

https://blog.csdn.net/zhang_referee/article/details/88212695

CentOS7安装mysql8.0编译报错集合

https://www.cnblogs.com/NanZhiHan/p/11017158.html

无密码登录修改密码

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

或者

ALTER USER root IDENTIFIED BY '123456';

可能会出现报错

ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
mysql> use mysql
mysql> select user,host from user;

注意 root 的 host 是 localhost,所以语句修改为

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

退出 MySQL 刷新权限

mysql> flush privileges;

MySQL数据库如何修改密码

https://www.csdn.net/gather_27/MtTaIgysMzQxMC1ibG9n.html

开启外部访问(改表法)

mysql> use mysql
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;

或者(授权法)

mysql> grant all privileges  on *.* to root@'%' identified by "123456";
mysql> flush privileges;

开启MySQL远程访问权限 允许远程连接

https://www.cnblogs.com/weifeng1463/p/7941625.html

mysql中grant all privileges on赋给用户远程权限

https://blog.csdn.net/qq_31725371/article/details/83019856

关闭防火墙或设置 3306 端口外部访问

firewall-cmd --state
systemctl stop firewalld
#启动防火墙
systemctl start firewalld
#添加端口访问
firewall-cmd --permanent --add-port=3306/tcp
#重新加载防火墙配置
firewall-cmd --reload

发表评论

电子邮件地址不会被公开。 必填项已用*标注