1、下载 下载文件为:mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar (解压版) 2、卸载原来安装的mysql
#检查 rpm -qa | grep mariadb rpm -qa | grep mysql ​ #卸载 remove后为上面命令查询到的内容,全文件名 yum remove mariadb-xxx 3、解压文件到安装目录
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /data/module/ mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28 4、软连接
#在/usr/local/目录下创建到/data/module/mysql-5.7.28的软链接 cd /usr/local ln -s /data/module/mysql-5.7.28 mysql 5、添加mysql用户
#修改mysql目录权限,并用此用户执行应用 useradd -s /bin/false -M mysql cd /data/module chown -R mysql:mysql mysql-5.7.28 6、修改配置文件
#vim /etc/my.cnf ​ [mysqld] # binlog 配置 log-bin=/usr/local/mysql/logs/mysql-bin.log expire-logs-days=14 max-binlog-size=500M server-id=1 # GENERAL basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock user=mysql default-storage-engine=InnoDB character-set-server=utf8 lower_case_table_names = 1 explicit_defaults_for_timestamp=true [mysqld_safe] log-error=/usr/local/mysql/mysql-error.log pid-file=/usr/local/mysql/mysqld.pid [client] socket=/usr/local/mysql/mysql.sock [mysql] default-character-set=utf8 socket=/usr/local/mysql/mysql.sock 7、安装mysql
cd /data/module/mysql-5.7.28 bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ​ 报错! 在/usr/local/mysql/下创建 logs 文件夹就行了,并改为mysql用户。 执行成功后,不要动此窗口,有初始密码需要复制 8、拷贝启动程序
# 再开一个窗口 将mysql的启动程序拷贝到/etc/init.d/目录下 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 9、启动mysql
service mysqld start # 如果报错,可能是mysql-error.log不存在,手动去创建,并修改权限 cd /data/module/mysql-5.7.28 touch mysql-error.log chown mysql:mysql mysql-error.log ​ # 再次启动 10、配置环境变量
# vim /etc/profile 增加 ​ #mysql export MYSQL_HOME=/usr/local/mysql export PATH=$PATHMYSQL_HOME/bin ​ 改完 source /etc/profile 11、修改密码
mysql -uroot -p # 密码为第7步生成的初始密码 ​ mysql> alter user 'root'@'localhost' identified by '000000'; mysql> flush privileges; 12、开启远程连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 13、开机自启配置
chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig --list # 345为on chkconfig --level 345 mysqld on 14、登录更改
登录 mysql -uroot -p -P3306 -A use mysql; update user set host = '%' where user = 'root'; flush privileges; 修改密码
mysql> update user set password=password("*******") where user="*******"; #修改密码报错 ERROR 1054 (42S22): Unknown column 'password' in 'field list' mysql> update mysql.user set authentication_string=password('*******') where user='*******'; #修改密码成功 Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 ​ flush privileges;
|