前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >centos6上使用yum方式安装MySQL

centos6上使用yum方式安装MySQL

作者头像
JaneYork
发布2023-10-11 14:37:54
9650
发布2023-10-11 14:37:54
举报
文章被收录于专栏:PUSDN平行宇宙软件开发者网

系统:centos6

mysql:5.1.73 /8.0.18

一、直接yum默认源安装。

1.检查是否安装了MySQL。

代码语言:javascript
复制
rpm -qa | grep mysql
代码语言:javascript
复制
rpm -e mysql    //普通删除模式,有时候会提示依赖于其他文件,无法删除。
# 强力删除模式,用该命令强力删除
rpm -e --nodeps mysql
rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64

2.下载安装。

代码语言:javascript
复制
# 查看yum上可下载的MySQL
yum list | grep mysql
# 安装
yum install -y mysql-server mysql mysql-devel

3.初始化及配置。

代码语言:javascript
复制
# 启动
service mysqld start
# 检查是否开机启动
chkconfig --list | grep mysqld
代码语言:javascript
复制
# 设置root密码
mysqladmin -u root password 'nishipogaizaima'
# 登录,输入刚才设置的密码
mysql -u root -p
代码语言:javascript
复制
# 修改字符编码
cp /usr/share/doc/mysql-server-5.1.73/my-large.cnf /etc/my.cnf
vim /etc/my.cnf
# 在[client]下增加default-character-set=utf8字段
# 在[mysqld]下增加default-character-set=uft8字段(起不来)
# 重启服务
service mysqld restart
#yum默认安装位置
# 数据库目录
/var/lib/mysql/
# 配置文件
/usr/share /mysql(mysql.server命令及配置文件)
# 相关命令
/usr/bin(mysqladmin mysqldump等命令)
# 启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)
代码语言:javascript
复制
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password	= your_password
port		= 3306
socket		= /var/lib/mysql/mysql.sock
default-character-set=utf8

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port		= 3306
socket		= /var/lib/mysql/mysql.sock
skip-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id	= 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

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

[mysqlhotcopy]
interactive-timeout

二、指定yum源安装。

仓库源都给你了,还想怎样?https://dev.mysql.com/downloads/repo/yum/

这里下载centOS6

代码语言:javascript
复制
cd /home/
wget https://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm
# 安装
yum -y localinstall mysql80-community-release-el6-3.noarch.rpm
# 或
rpm -Uvh mysql80-community-release-el6-3.noarch.rpm

#安装成功后在/etc/yum.repos.d/下会多出几个mysql的yum源的配置

代码语言:javascript
复制
ls -lh  /etc/yum.repos.d/

查看是否可用: yum repolist enabled | grep mysql

代码语言:javascript
复制
# 安装,网速慢,失败,可重新执行
yum -y install mysql-community-server
# 查看MySQL版本
mysql -V
# 启动,失败可重试
service mysqld start
# 重启
service mysqld restart

查看root默认密码:

cat /var/log/mysqld.log | grep root@localhost

修改密码: 

mysql -u root -p

输入密码进入MySQL命令行,执行任何操作都提示你要修改密码:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

代码语言:javascript
复制
set password=password('nishipogaizaima');
alter user 'root'@'localhost' password expire never;
flush privileges;

下载慢,改为国内yum源:https://blog.csdn.net/qq_31708763/article/details/102999274

代码语言:javascript
复制
ls /etc/yum.repos.d/*.repo
以repo结尾的都是正在使用的yum源站

MySQL8修改密码:

代码语言:javascript
复制
# 建议使用复杂密码,否则提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
ALTER user 'root'@'localhost' IDENTIFIED BY 'Woshipogaizai123$$';
# 刷新权限
flush privileges;
# 退出
exit;

额外:

Linux上MySQL卸载:https://blog.csdn.net/qq_31708763/article/details/86485398

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档