Linux下mysql的安装与配置

2022-12-21 19:09:00 浏览数 (1)

yum源安装MySQL和开启设置服务

  首先,我们来看看使用yum源安装MySQL的优缺点:

  优点:安装方便快捷,安装方式简单

  缺点:太过于死板,定死了各个文件的位置

1、在 Centos7 系统下使用 yum 命令安装 MySQL,需要注意的是 CentOS 7 版本中 MySQL数据库已从默认的程序列表中移除,所以在安装前我们需要先去官网下载 Yum 资源包,下载地址为:https://dev.mysql.com/downloads/repo/yum/

代码语言:javascript复制
wget https://dev.mysql.com/get/mysql57-community-release-el7-1.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install mysql-server

/etc/yum.repos.d/mysql-community.repo

代码语言:javascript复制
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
代码语言:javascript复制
 yum install mysql-community-server

初始化 MySQL:

代码语言:javascript复制
mysql_secure_installation

启动 MySQL:

代码语言:javascript复制
 systemctl start mysqld.service

查看 MySQL 运行状态:

代码语言:javascript复制
 systemctl status mysqld.service

注意:如果我们是第一次启动 mysql 服务,mysql 服务器首先会进行初始化的配置。

参考:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

二进制安装mysql和开启设置服务

1、卸载MariaDB     CentOS7默认安装了和MySQL有兼容性的MariaDB数据库,在我们安装MySQL5.7之前为了避免发生冲突首先删除MariaDB。     # rpm -qa | grep maria     yum remove mariadb-libs -y 2、安装环境 yum -y install make cmake bison-devel ncurses-devel gcc gcc-c kernel-devel && yum install -y readline-devel pcre-devel openssl-devel openssl zlib zlib-devel pcre-devel  perl perl-devel wget 3、下载boost,一定要是1_59_0 wget -c https://dl.bintray.com/boostorg/release/1.59.0/source/boost_1_59_0.tar.gz tar -xzvf boost_1_59_0.tar.gz cp boost_1_59_0 /usr/local/ 4、安装mysql wget -c https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22.tar.gz && tar -zxvf mysql-5.7.22.tar.gz && rm -f mysql-5.7.22.tar.gz && cd mysql-5.7.22

代码语言:javascript复制
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc 
-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock 
-DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all 
-DMYSQL_USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost_1_59_0

gmake && make install

5、安装之后的一些配置: cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

mkdir /var/lib/mysql

chown mysql. mysql

vi /etc/my.cnf

[mysqld]

basedir = /usr/local/mysql

datadir = /var/lib/mysql

port = 3306

socket = /tmp/mysqld.sock

mysql_install_db 被废弃了,取而代之的是 mysqld –initialize

# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --datadir=/var/lib/mysql --basedir=/usr/local/mysql --user=mysql

# systemctl start mysql

# ps -ef|grep mysql

# vi ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

ln -s /usr/local/mysql/bin/mysql /usr/bin

# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

配置文件中添加如下一行,跳过密码验证

# cat /etc/my.cnf

[mysqld]

skip-grant_tables

重启MySQL

# systemctl restart mysql

# mysql

mysql> update mysql.user set authentication_string=password('Oracle') where user='root' ;

0 人点赞