Yum Mysql

  • A+
所属分类:Mysql

系统版本: Centos 7

mysql版本: 5.7

自带yum源版本太低,安装高版本mysql最好还是更新mysql repo源

1.查看Centos6是否安装mysql

rpm -qa | grep mysql

 2.若有自带mysql,卸载Centos

rpm -e rpm包;
rpm -e –nodeps  不检查依赖包直接删除
rpm -e –alimatches –nodeps rpm  删除相同名字包,并忽略依赖包
yum -y remove rpm包  若有多个依赖包依次卸载,当结果显示Complete!表示卸载完毕

3.官网下载mysql yum并安装

rpm -ivh  https://repo.mysql.com//mysql57-community-release-el7.rpm

4. 查看 yum库上mysql版本信息

yum repolist enabled | grep mysql

如没有发现,需配置repo,注意如果要使用5.6或其他版本,只能有一个enabled=1,其他enable=0

5.yum安装mysql

yum install mysql-community-server -y

6.启动mysql

systemctl start mysqld;
systemctl enable mysqld;

查看mysql密码
grep 'password' /var/log/mysqld.log |head -n1

7.登录mysql并设置密码

mysql -u root -p
set password =password('Thege@123');
flush privileges;

或者也可用
alter user 'root'@'localhost' identified by 'Thege@123';

root密码设置成Thege@123

8.修改配置文件(仅供参考)

mv /etc/my.cnf /etc/my.cnf.bak;
tee -a  /etc/my.cnf <<-'EOF'
[client]
port        = 3307
socket      = /var/lib/mysql/mysql.sock
[mysqld]
port        = 3307
socket      = /var/lib/mysql/mysql.sock
datadir = /var/lib/mysql 
character-set-server=utf8 
collation-server=utf8_general_ci 
skip-external-locking 
key_buffer_size = 128M 
max_allowed_packet = 32M 
table_open_cache = 512
net_buffer_length = 8K
sort_buffer_size = 2M 
read_buffer_size = 16M 
read_rnd_buffer_size = 160M 
myisam_sort_buffer_size = 32M 
thread_cache_size = 64 
query_cache_size= 64M
tmp_table_size = 64M
max_connections = 5000
max_user_connections = 5000
max_connect_errors = 6000
wait_timeout = 30 
interactive_timeout = 30 
long_query_time = 1 
log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
expire_logs_days = 10
early-plugin-load = ""
open_files_limit = 3000
log_slave_updates = 1

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
sync_binlog = 1

[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 2M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
EOF

修改后,重启服务
systemctl restart mysqld

9.添加防火墙策略

firewall-cmd --zone=public --add-port=3307/tcp --permanent;firewall-cmd --reload

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: