1. 下载Mysql安装包,解压到指定的目录
新建用户 :useradd -r -g mysql mysql
在线解压的目录下新建 目录 data、etc、logs以及文件my.cnf,内容如下
[mysqld]
# skip-grant-tables //忘记密码的操作
datadir=/usr/local/tools/mysql/mysql-master-3307/data //自己的目录
basedir=/usr/local/tools/mysql/mysql-master-3307 //自己的目录
socket=/usr/local/tools/mysql/mysql-master-3307/etc/mysql.sock //自己的目录
log-bin=//usr/local/tools/mysql/mysql-master-3307/logs/mysql-bin //自己的目录
port=3307
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
# sql_mode=
# character set
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
# slow query
slow_query_log=on
slow_query_log_file=/usr/local/tools/mysql/mysql-master-3307/logs/slow-query.log //自己的目录
[client]
port=3307
socket=/usr/local/tools/mysql/mysql-master-3307/etc/mysql.sock //最好有
[mysqld_safe]
log-error=/usr/local/tools/mysql/mysql-master-3307/logs/error.log //自己的目录,新建error.log 文件
pid-file=/usr/local/tools/mysql/mysql-master-3307/etc/mysqld.pid //自己的目录
2.初始化安装
./mysqld --defaults-file=/usr/local/tools/mysql/mysql-master-3307/my.cnf --initialize --user=mysql --basedir=/usr/local/tools/mysql/mysql-master-3307 --datadir=/usr/local/tools/mysql/mysql-master-3307/data
!!!这个时候密码会打印,记住密码,这个过程有些小长,不可自己关闭。
3.启动mysql实例
./mysqld_safe --defaults-file=/usr/local/tools/mysql/mysql-master-3307/my.cnf & //自己的my.cnf 的位置
4.登录mysql
可能会出现:error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
处理:sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
登录命令:
./mysql -uroot -p -S /usr/local/tools/mysql/mysql-master-3307/etc/mysql.sock //多个必须使用这个,自己的mysql.sock的位置
输入初始化时候的密码
5.进行新建用户操作
切换数据库:use mysql;
会提示修改密码,修改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY '自己的密码';
查询用户:select user,host from user;
创建远程连接用户:create user root@'%' identified by '自己的密码';
远程连接用户授权:grant all privileges on *.* to root@'%' with grant option;
刷新权限:flush privileges;
修改远程连接用户的加密规则:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '自己的密码';
建议再次刷新权限:flush privileges;
6.开机启动
编辑:vim /etc/rc.d/rc.local
添加内容如下:
# mysql 开机自启动
/usr/local/tools/mysql/mysql-master-3307/bin/mysqld_safe --defaults-file=/usr/local/tools/mysql/mysql-master-3307/my.cnf & //自己的文件位置
/usr/local/tools/mysql/mysql-slave-3308/bin/mysqld_safe --defaults-file=/usr/local/tools/mysql/mysql-slave-3308/my.cnf &
//自己的文件位置
添加文件的执行命令:chmod +x /etc/rc.d/rc.local