mysql安装

1、下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
2、解压复制到mysql目录
tar -zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
cp -r mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql
3、添加名叫用户组(如果有就跳过)
groupadd mysql
4、添加用户
useradd -r -g mysql mysql
5、进行到解压后的mysql目录,然后新建文件
cd /usr/local/mysql
mkdir ./data/mysql
6、修改目录的权限
chown -R mysql:mysql ./
7、初始化安装mysql

==这是5.6版本,如果是5.7的话有很大的不同==

./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
8、修改启动脚本
vi /etc/init.d/mysqld
修改的内容是
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
9、启动服务
service mysqld start
10、测试连接(在mysql目录下)
/bin/mysql -uroot
11、加入环境变量,可以随便在其它地方启动关闭
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
12、更改登录密码
 cd /usr/local/mysql/
./bin/mysqladmin -u root -h localhost.localdomain password 'root'
13、登录、
./bin/mysql -h127.0.0.1 -uroot -proot
登录后可以修改其它密码
update mysql.user set password=password('root') where user='root'; flush privileges;
14、这时还不能远程连接,增加远程连接
grant all privileges on *.* to root@'%' identified by 'root'; flush privileges;
服务的启动、关闭,查看状态

启动mysql

service mysqld start

关闭mysql

service mysqld stop

查看运行状态

service mysqld status

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