1.使用 Xftp 把 mysql 压缩包放入 linux 的 usr/local 目录下,并解压 mysql
tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
2.删除 mysql 的压缩包,之后输入 y,即可删除 mysql 的压缩包
rm mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
3.移动并重命名 mysql
mv /usr/local/mysql-5.7.27-linux-glibc2.12-x86_64 /usr/local/mysql
4.创建用户和用户组
groupadd mysql
useradd -r -g mysql mysql
5.将安装目录所有者及所属组改为 mysql ,这个根据自己的目录来
chown -R mysql.mysql /usr/local/mysql
6.在 mysql 目录下创建 data 文件夹
mkdir /usr/local/mysql/data
7.初始化数据库
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/
--datadir=/usr/local/mysql/data
出现上述警告不用管!!!
8.完成初始化后编辑配置文件 /etc/my.cnf ,如下:
vi /etc/my.cnf
先输入‘i’或‘a’或‘o’后,对照修改以下内容
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
#跳过验证,忘记 可以设置,然后修改,再关闭
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# include all files from the config directory
!includedir /etc/my.cnf.d
9.设置 mysql passwd(因为在配置文件取消了PASSWD验证,可以直接回车键)
配置 mysql 环境变量
vi /etc/profile
先输入‘i’或‘a’或‘o’后,在文件最后添加以下内容
export PATH=$PATH:/usr/local/mysql/bin
使用命令使配置文件生效
source /etc/profile
将 mysql 加入到服务中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
mysql 服务开机启动
chkconfig mysql on
启动 mysql
service mysql start
如出现报错 log-error set to '/var/log/mariadb/mariadb.log', however file
don't exists. Create writable for user 'mysql'.
用 WinSCP 去看的时候发现并没有/var/log/mariadb/mariadb.log 这个路径,那我们就创建, 并给
mysql
用户授权即可
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
————————————————
查看 mysql 初始passwd cat /root/.mysql_secret
C/;x:k?>:0u.
mysql 登录成功,再操作数据库设置passwd use mysql;
update user set authentication_string=password('root') where user='root';
flush privileges;
quit;
选择数据库:use mysql;
5.7 以 上 版 本
运 行 : update user set password= password("newPassword")where user='root';
5.7 以 下 版 本 运 行 : update user set authentication_string= password(‘newPassword’)where user='root';
mysql> alter user "root"@"localhost" identified by "新passwd";
之后,重新编辑 mysql 配置文件
vi /etc/my.cnf 将 /etc/my.cnf 中skip-grant-tables删除或注释掉,并更改mysql大小写敏感
问题
在 /etc/my.cnf 的 mysqld 添加 lower_case_table_names=1 接着按 esc 退出编辑,再按 Shift+q,然后输入:wq!保存并退出
然后重启 mysql :service mysql restart
配置 mysql 远程连接,进入 mysql 内输入一下命令
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
之后,配置 mysql 端口号 3306,并重启防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload
如果进行操作出现下面的提示:
就重新设置一遍passwd(原passwd):
alter user 'root'@'localhost' identified by'root';
exit;
10. 最后通过 navicat 进行远程连接测试出现更改完passwd错误: