下载MySQL安装包,并上传到Linux服务器上
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
解压
[root@localhost tmp]# tar -xzvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
修改目录
[root@localhost ~]# mv /usr/local/mysql-5.7.26-linux-glibc2.12-x86_64/ /usr/local/mysql
创建用户和组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
更改目录所有者及所属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
创建data目录
[root@localhost mysql]# mkdir data
安装依赖包
[root@localhost mysql]# yum install libaio
进行初始化
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
修改配置
[root@localhost mysql]# vim /etc/my.cnf
[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
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
将MySQL加入到服务中
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
开机启动
[root@localhost mysql]# chkconfig mysql on
启动MySQL服务
[root@localhost mysql]# service mysql start
登陆MySQL,在配置文件/etc/my.cnf中跳过密码登陆,所以可以免密登陆
[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p
查看用户
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
查看数据库
mysql> show databases;
登录MySQL后,由于配置免密登录,刷新权限后即可重新设置密码
mysql> flush privileges;
更改root密码
mysql> set password for root@localhost=password('123456');
创建用户
mysql> CREATE USER 'tfdb'@'localhost' IDENTIFIED BY '123456';
赋予所有权限
mysql> GRANT ALL PRIVILEGES ON *.* TO "tfdb"@"%" IDENTIFIED BY "123456" WITH GRANT OPTION;
如果flush privileges;刷新权限后退出了MySQL,再次登录的时候会提示失败,需要重启MySQL服务
[root@localhost mysql]# service mysql start