安装mysql记录
记录一下哎.主要是操作过程.
环境Centos7
下载
下载页面连接在这里https://dev.mysql.com/downloads/mysql/
这里Select Operating System:我选择的是Linux - Generic
,这个时候下面的mysql版本是8.0的,点一下选择框右边的Looking for previous GA versions?
即可看到5.7的.
这里下载Select OS Version:这里选择64位的,现在一般都是64位的,具体对应自己的系统.
然后下载
这里给个直链https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
开始安装操作
下载及解压
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz //下载
tar -zvxf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz //解压
mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql //把解压的文件放到 /usr/local/mysql 也就是安装到这里
添加mysql用户
小记:
/etc/passwd //这个文件存储用户相关信息
/etc/group //这个文件存储用户组相关信息
id 用户名 //查看用户的uid gid group
添加一个mysql用户useradd -r -s /sbin/nologin mysql
给上面的mysql目录的权限给这个用户chown -R mysql:mysql /usr/local/mysql
,其中mysql:mysql的对应关系是[所有者]:[组]
卸载mariadb-libs
网上是这样卸载:
yum remove mariadb-libs
过程输入y确认即可卸载完成.
我用的方法是
rpm -qa|grep mariadb //如果有安装的话此时返回信息 我这里返回的是mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 //这一步末尾参数输入上面返回的信息,如果上面没有返回,就说明无需卸载
配置my.cnf
mkdir -p /data/mysql //这里创建目录存储数据库等文件 也就是my.cnf中的datadir
chown -R mysql:mysql /data/mysql //授权
这里是数据库的一些配置
写入文件/etc/my.cnf
内容为
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="MySQL [\d]> "
no-auto-rehash
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 326
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
初始化
在/usr/local/mysql
这个目录中,只是装好了软件,但是不能运行,就像一个壳子,没有数据文件夹.
执行初始化操作,生成数据文件,这里初始化和上面my.cnf文件里面的配置有关
cd /usr/local/mysql //进入软件目录
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
执行完毕后可在/data/mysql/mysql-error.log
这个文件中看到root账户密码
2021-07-11T01:38:05.769656Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-07-11T01:38:05.857415Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-07-11T01:38:05.933919Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a3a8bc7b-e1e8-11eb-9b8c-00b505471858.
2021-07-11T01:38:05.936104Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-07-11T01:38:07.458744Z 0 [Warning] CA certificate ca.pem is self signed.
2021-07-11T01:38:07.672249Z 1 [Note] A temporary password is generated for root@localhost: 0u0eJJ5yaP+9
root@localhost: 0u0eJJ5yaP+9
,这个就是账户和密码.
如果以后想要重建数据库,直接删除'/data/mysql'目录内的所有文件.重新初始化一下就好了.
配置开机自启
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/ //复制自带的服务文件
chmod +x /etc/init.d/mysql.server //给与执行权限
chkconfig --add mysql.server //添加服务
配置完之后就支持systemctl命令控制了.
执行systemctl start mysql
启动.
其他命令:
systemctl stop mysql
停止,systemctl restart mysql
重启.systemctl status mysql
查看状态.
配置命令
老方法建个软连接过去
ln -s /usr/local/mysql/bin/mysql /usr/sbin/
ln -s /usr/local/mysql/bin/mysql /usr/bin/
此时输入mysql -uroot -p
然后输入密码确认,即可成功通过控制台使用mysql.
进去后第一步要先设置一下密码在进行别的操作
更改密码
alter user user() identified by "XXXXXX";
XXXXXX即为设置的密码.
允许远程连接
切换数据库use mysql;
查询数据select host, user from user;
,正常情况下看到的是
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
把localhost改成%,即可.update user set host = '%' where user = 'root';
此时再查询select host, user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
所有操作后刷新权限
执行
FLUSH PRIVILEGES;
创建用户及数据库
创建一个study用户,密码也是study,允许所有IP连接create user 'study'@'%' identified by 'study';
创建一个数据study
CREATE DATABASE
study CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';
授予study数据库的所有权限
GRANT ALL PRIVILEGES ON study.* TO 'study'@'%';
查看权限show grants for study;
+--------------------------------------------------+
| Grants for study@% |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO 'study'@'%' |
| GRANT ALL PRIVILEGES ON `study`.* TO 'study'@'%' |
+--------------------------------------------------+
2 rows in set (0.00 sec)
所有操作后刷新权限
执行
FLUSH PRIVILEGES;
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »