linux 安装 mysql


# mysql-5.7.18-linux-glibc2.5安装
1.检查所使用的linux下是否有安装过mysql
rpm -qa|grep -i mysql
2.删除安装过的mysql
rpm -e mysql-5.7.13-linux-glibc2.5-x86_64 --nodeps //载时使用了--nodeps选项,忽略了依赖关系
3.创建mysql的用户组/用户, data目录及其用户目录
userdel mysql

groupdel mysql

--

mkdir -p /data/mysql/app

mkdir -p /data/mysql/data

groupadd mysql

useradd -g mysql -M mysql

chown -R mysql:mysql /data/mysql/app

4.解压安装包并将解压包里的内容拷贝到mysql的安装目录/data/mysql/app
tar -xzvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.7.18-linux-glibc2.5-x86_64/* /data/mysql/app

rm -rf mysql-5.7.18-linux-glibc2.5-x86_64
5.初始化mysql数据库
/data/mysql/app/bin/mysqld --user=mysql --basedir=/data/mysql/app --datadir=/data/mysql/data --initialize

####初始化出现错误的时候
--/data/mysql/app/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
使用命令---yum install -y libaio
jOifU#&sw6dd
---
tN4>UMM?eD#2
---
frWBuknjw8&t

6.复制mysql服务启动脚本及加入PATH路径

sed -i '52a\export PATH=/data/mysql/app/bin:/data/mysql/app/lib:\$PATH' /etc/profile

source /etc/profile

7. 复制mysql服务启动配置文件

1. cp /data/mysql/app/support-files/mysql.server /etc/init.d/mysqld

2. chmod a+x /etc/init.d/mysqld

3. vi /etc/my.cnf
添加:
------------------------------------------------------------------------------------------------#
[mysqld]
datadir=/data/mysql/data
basedir =/data/mysql/app
socket=/data/mysql/app/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0


join_buffer_size = 8M
sort_buffer_size = 8M
read_rnd_buffer_size = 8M
innodb_buffer_pool_size = 16G
max_connections=2000
max_allowed_packet = 20971520
lower_case_table_names=1
tmp_table_size=1073741824
max_heap_table_size=1073741824
query_cache_size=4M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
general_log=on(默认关闭,off)
gtid_mode=ON
enforce_gtid_consistency = ON


# 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/mysql.log
pid-file=/var/run/mysql.pid


[client]
socket=/data/mysql/app/mysql.sock
#
# include all files from the config directory
#


------------------------------------------------------------------------------------------------#


8.启动mysql服务并加入开机自启动
service mysqld start

chkconfig --level 35 mysqld on
9.检查mysql服务是否启动
netstat -tulnp |grep 3306

10.修改root默认密码
mysql -u root -p

alter user 'root'@'localhost' identified by '123ewQ!@#';

flush privileges;

11. 创建数据库及用户并授权 (db_name为数据库名称)
CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;(新建test_ejob)

grant all privileges on ming_dao.* to mingdao@'%' identified by '789oiU&*';(%:任何地方都能登录,不限制IP;localhost:只能本服务器登录;10.10.40.142:)
(all privileges:所有权限;select:查询权限)grant all privileges on *.* to root@'%'  WITH GRANT OPTION
(grant select,update on test_ejob.* to test_tmzl@'%' identified by '789oiU&*';)


use mysql
select host,user from mysql.user;(查询系统所有用户)
Delete FROM user Where User='carlife' and Host='%';(删除某个mysql用户:先进入use mysql,然后再删除,根据User和Host为唯一主键)

grant all privileges on carlife.* to clms@'%' identified by '789oiU&*';


==========================故障处理==========================
(输入exit退出先)
1. 忘记默认密码处理方式:
vi /etc/my.cnf

添加:skip-grant-tables

重启mysql: service mysqld restart

进入mysql:mysql -u root -p 回车,跳过密码,不用输入

mysql>update mysql.user set authentication_string=password('123$%ZAQ!') where user='root' and Host = 'localhost';

exit

vi /etc/my.cnf

删除 skip-grant-tables

重启mysql

service mysqld restart




2.mysql 8 报错 caching-sha2-password 时的处理方法
#创建用户

CREATE USER 'nfl_risk'@'%' IDENTIFIED BY 'nfl_risk';

#授权用户权限

grant all privileges on nfl_risk_t2.* to 'nfl_risk'@'%';

#客户端连接报错时的处理方法(在安装mysql8的时候如果选择了密码加密,之后用客户端连接比如navicate,会提示客户端连接caching-sha2-password,是由于客户端不支持这种插件,可以通过如下方式进行修改:)

ALTER USER 'nfl_risk'@'%' IDENTIFIED BY 'nfl_risk' PASSWORD EXPIRE NEVER;

ALTER USER 'nfl_risk'@'%' IDENTIFIED WITH mysql_native_password BY '{nfl_risk}';

 

posted @ 2021-10-13 16:20  dark_one  阅读(59)  评论(0编辑  收藏  举报