#卸载系统自带的Mariadb
#rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
#rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
检查mysql是否存在
#rpm -qa | grep mysql
#创建一个用户名为mysql的用户并加入mysql用户组
#useradd -s /sbin/nologin mysql 禁止mysql登陆
#cd /usr/local/
#tar -xvzf /root/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
#mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
#更改所属的组和用户
#chown -R mysql:mysql mysql
#mkdir /var/run/mysqld
#chown mysql:mysql /var/run/mysqld
编辑配置文件
#vi /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
skip-name-resolve
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=1000
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=100M
pid-file=/var/run/mysqld/mysqld.pid
#开启binlog日志
log-bin=mysql-bin
server-id=1
expire_logs_days=30
初始化
#cd mysql
#bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
#cp ./support-files/mysql.server /etc/init.d/mysqld
#chown 755 /etc/my.cnf
#chmod +x /etc/init.d/mysqld
#/etc/init.d/mysqld start
#设置开机启动
#chkconfig --level 35 mysqld on
#chkconfig --list mysqld
#chkconfig --add mysqld
#service mysqld status
#systemctl restart mysqld
设置软链接
#ln-s /usr/local/mysql/bin/mysql /usr/bin/
获得初始密码
#cat /root/.mysql_secret
Password set for user ‘root@localhost’ at 2017-04-17 17:40:02
_pB*3VZl5T<6
修改密码
mysql -uroot -p
Enter password:
mysql> set PASSWORD = PASSWORD(‘111111’);
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
添加远程访问权限
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host=’%’ where user=‘root’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user from user;
±----------±----------+
| host | user |
±----------±----------+
| % | root |
| localhost | mysql.sys |
±----------±----------+
2 rows in set (0.00 sec)
create user ‘xxx’@’%’ identified by ‘123’; 这里 @‘%’ 表示在任何主机都可以登录
log_timestamps=SYSTEM #此设置解决mysql日志时间和实际系统时间相差8小时,因为默认使用的是美国时间
default-time-zone = “+08:00” 修改时区为东八区
log-error=/var/log/mysqld.log 设置Mysql日志文件位置,
设置一下时间 然后重启数据库
为了安全一般不给root远程访问权限 可以再创建一个别的用户,并给他远程访问权限
grant all privileges on . to anycfs@’%’ identified by ‘anycfs123’;
flush privileges;