1.mysql数据库官网
2.编译安装
yum install -y gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel
useradd -s /sbin/nologin mysql(添加mysql用户)
cd /usr/local/
wget 'https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.39.tar.gz'
tar -zxvf mysql-5.6.39.tar.gz
cd mysql-5.6.39
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL=yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1(cmake编译安装,依次,安装的路径,数据存放的路径,使用的字符集)
make && make install
cp support-files/mysql.server /etc/init.d/mysqld(拷贝server文件到init.d下)
chmod a+x /etc/init.d/mysqld(赋予执行权限)
3.mysql环境变量配置
export PATH=$PATH:/usr/local/mysql/bin/
4.更新mysql配置/etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow.log
expire_logs_days=2
innodb-file-per-table=1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 512M
connect_timeout = 60
net_read_timeout = 120
[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
5.mysql数据库初始化
mkdir -pv /data/mysql
chown -R mysql:mysql /usr/local/mysql /data/mysql/
yum install -y perl-Module-Install(安装perl模块)
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/
cd /data/mysql 可以看到三个初始化的数据库
6.使用systemctl管理mysqld,vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
[Install]
WantedBy=multi-user.target
7.启动数据库
systemctl start mysqld
8.mysql的安全方式
默认让127.0.0.1访问,用户名root,不需要密码
mysql -uroot -h 127.0.0.1
9.mysql加密码
mysqladmin -h 127.0.0.1 -u root password '123456'
mysql -h 127.0.0.1 -uroot -p123456
10.mysql授权某ip登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.237.%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;(刷新数据库)
(指定237网段的IP可以远程访问,ALL PRIVILEGES所有权限,还可以单独设置查询,修改权限)
11.网络登录mysql(另一台服务器)
mysql -h 192.168.237.49 -uroot -p123456
标签:log,local,mysql5.6,Centos7,编译,mysqld,usr,mysql,data
来源: https://www.cnblogs.com/wangchengliang/p/10829750.html