安装mysql

yum安装mysql

1、下载yum库或者RPM包

2、编写配置文件

vim  /etc/yum.repos.d/文件名mysql.repo

[文件名]

(变量)name=(需要变量的字符串)mysql-comm

(解析的地址变量)=(地址)ftp://(ip地址/下载包的目录地址)

3、(查询安装包)yum list |grep mysql-community-server

  (安装mysql包)yum intall -y (包名)mysql-community*

4、(启动数据库)systemctl start mysqld

    (开机启动) systemctl enable mysqld

5、(验证)ls /var/lib/mysql

    (查看相关文件)netstat -anpt |grep mysql

6、(查询登录密码)grep 'password' /var/log/mysqld.log

    (使用密码登录)mysql -uroot -p'密码'

    (修改密码)  ALTER USER 'root'@'localhost' IDENTIFIED BY 'QianFeng@123';



源码安装yum

#1、部署环境

yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake

#2、准备源码包

#创建用户组和用户并给用户权限

groupadd mysql

useradd -r -g mysql -s /bin/false mysql

tar xvf mysql-5.7.19.tar.gz

cd mysql-5.7.19

mv ../boost_1_59_0.tar.gz  .

tar xf  boost_1_59_0.tar.gz

#3编译前配置

cmake . \

-DWITH_BOOST=boost_1_59_0/ \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DSYSCONFDIR=/etc \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DINSTALL_MANDIR=/usr/share/man \

-DMYSQL_TCP_PORT=3306 \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_READLINE=1 \

-DWITH_SSL=system \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1

#4、编译

make

#安装

make install

#5、初始化安装位置

cd /usr/local/mysql

#创建一个目录,并设置权限

mkdir mysql-files

chown -R mysql.mysql /usr/local/mysql

#查找mysql临时密码(并保存)

/usr/local/mysql/bin/mysqld --initialize --user=mysql --bsaedir=/usr/local/mysql --datadir=/usr/local/mysql/data

/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

#创建mysql配置文件mysql.cnf

vim /etc/mysql.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

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

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start

ps aux |grep mysqld

mysql -u root -p '密码'  登陆有问题吗?

/usr/local/mysql/bin/mysql -u root -p'x/dwiQ2

#重置密码

/usr/local/mysql/bin/mysqladmin -u root -p 'x/dwiQ2

#查看库

show databases;

你可能感兴趣的:(安装mysql)