1、linux版本
[jimmy@localhost etc]$ cat /etc/redhat-release
CentOS Linux release7.5.1804 (Core)
2、MySQL版本
MySQL Community Server 5.7.29
mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
最好用迅雷下载,很快
3、添加用户 mysql
useradd mysql
4、拷贝MySQL包到 /usr/local/mysql
tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz mysql
5.编辑配置文件
cp /home/mysql-5.7.26-linux-glibc2.12-x86_64/support-files/my-default.cnf /etc/my.cnf
//如果没有my-default.cnf,就直接编辑/etc/my.cnf
[mysqld]
port=3306
#设置安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/tmp/mysql.sock
user=mysql
tmpdir=/usr/local/mysql/tmp
#开启ip绑定
#bind-address = 0.0.0.0
#允许最大连接数
max_connections=200
#服务端使用的字符集默认为8比特编码的latin1字符集
#MySQL的“utf8mb4”是真正的“UTF-8”
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
innodb_buffer_pool_size=64MB
max_allowed_packet=16M#表名忽略大小写,参数默认在Windows为1,在Unix中为0lower_case_table_names=1
[mysqld_safe]
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid
[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
#指定客户端连接mysql时的socket通信文件路径
socket=/usr/local/mysql/tmp/mysql.sock
default-character-set=utf8mb4
!includedir /etc/my.cnf.d
6.初始化mysqld
[mysql@smallcloud mysql5.7.26]$ ./bin/mysqld --initialize --user=mysql --basedir=/home/mysql/mysql5.7.26 --datadir=/home/mysql/mysql5.7.26/data
//启动mysql服务:
[mysql@smallcloud mysql5.7.26]$ ./support-files/mysql.server start
7.设置开机启动
//复制启动脚本到资源目录(需要新建mysqld文件夹)
[root@smallcloud ~]# cp /home/mysql/mysql5.7.26/support-files/mysql.server /etc/init.d/mysqld
// 增加 mysqld 服务控制脚本执行权限:
[root@smallcloud ~]# chomod +x /etc/rc.d/init.d/mysqld
//将 mysqld 服务加入到系统服务:
[root@smallcloud home]# chkconfig --add mysqld
//检查mysqld服务是否已经生效:
[root@smallcloud home]# chkconfig --list mysqld
8.设置环境变量
[root@smallcloud home]# vim /home/mysql/.bash_profile
export PATH=$PATH:/home/mysql/mysql5.7.26/bin
[root@smallcloud home]# source /home/mysql/.bash_profile
9.登录及更改密码
[mysql@smallcloud ~]$ mysql -uroot -p
mysql> set password=password('密码')
mysql> quit
10.创建用户并授权
mysql> select user,host from user\G; //查看数据库的用户
mysql>create user 'myuser'@'%' identified by 'sjx1123';
mysql> grant all on *.* to 'myuser'@'%'; //授予用户所有权限,没有grant权限
11.mysql关闭开启
service mysqld start
service mysqld stop
service mysqld restart