mysql5.7.20安装
检查
rpm -qa|grep -i mysql 检查是否安装MySQL
rpm -e xxx --nodeps 卸载MySQL
下载
https://dev.mysql.com/downloads/mysql/ 选择Linux Generic通用版和Compressed TAR Archive压缩源码,选择不登陆直接下载 windows可选择推荐的MSI二进制exe下载安装
解压
tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
tar -xvJf mysql***.tar.xz 重命名 mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
添加组和用户
查看mysql组用户 groups mysql,查看用户组 vim /etc/group,查看当前登录用户组内成员 groups
新建组:groupadd mysql,添加用户 useradd -r -g mysql mysql,设置用户密码 passwd mysql
注:新建组和添加用户就行
新建数据存放文件夹
mkdir /app/deploy/mysql_data
修改权限
chown -R mysql:mysql /app/mysql
初始化
cd mysql ./bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/app/deploy/mysql_data,使用mysql_install_db安装已过时
注意保存初始密码,如:.?earEtwf4ft
如果报错:libaio.so.1,则:yum install libaio
修改权限
chown -R root:root /app/mysql
chown -R mysql:mysql /app/deploy/mysql_data
修改./support-files/mysql.server
basedir=/app/mysql datadir=/app/deploy/mysql_data
mysqld_pid_file_path不用设置,使用默认即可
复制添加为服务
cp -a ./support-files/mysql.server /etc/init.d/mysql
新版./support-files/my-default.cnf已删除,如果需修改配置,/etc目录下新建或修改my.cnf为:
[mysql]
default-character-set = utf8
[mysqld]
default-storage-engine = INNODB
character_set_server=utf8
lower_case_table_names=1
设置全局
#set for mysql export MYSQL_HOME=/app/mysql export PATH=$PATH:$MYSQL_HOME/bin
注:修改/etc/profile文件, 在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL上面
刷新配置:source /etc/profile
设置开机启动
chkconfig --level 35 mysql on
查看开机启动项:chkconfig
删除开机启动项:chkconfig --del mysql/php-fpm
启动/停止服务
service mysql start/stop 直接kill进程会自动nohup重启mysql_safe
查看配置
ps -ef|grep mysql
常用命令
show databases
show tables
status
quit
初始化密码
mysql -u root -p 输入之前保存的密码登陆 SET PASSWORD = PASSWORD('lizhaobin995'); flush privileges; 只有初始化后才能操作,不用flush会自动刷新
添加远程访问
use mysql; select host, user from user; update user set host = '%' where user = 'root';
重启服务
service mysql restart
mysql8.0.12安装
配置/etc/my.cnf
[mysqld] server-id = 1 port = 3306 mysqlx_port = 33060 mysqlx_socket = /tmp/mysqlx.sock datadir = /app/deploy/mysql_data socket = /tmp/mysql.sock pid-file = /tmp/mysqld.pid log-error = error.log slow-query-log = 1 slow-query-log-file = slow.log long_query_time = 0.2 log-bin = bin.log relay-log = relay.log binlog_format =ROW relay_log_recovery = 1 character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect ='SET NAMES utf8mb4' innodb_buffer_pool_size = 1G join_buffer_size = 128M sort_buffer_size = 2M read_rnd_buffer_size = 2M log_timestamps = SYSTEM lower_case_table_names = 1 default-authentication-plugin =mysql_native_password
初始化:
./bin/mysqld --user=mysql --lower-case-table-names=1 --initialize-insecure --basedir=/app/deploy/mysql --datadir=/app/deploy/mysql_data
修改密码:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '我的密码';