赞
踩
1,建立mysql 账户和组
sudo -i 作为root进行操作
[root@CDH-141 ~]# groupadd mysql # 创建mysql用户组
[root@CDH-141 ~]# useradd -g mysql mysql # 创建一个用户名为mysql的用户,并加入mysql用户组
[root@CDH-141 ~]# passwd mysql # 制定password 为111111 (用户mysql的密码)
2,移动文件
# 解压mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz [root@CDH-141 local]# tar -zxvf mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz [root@CDH-141 local]# mv mysql-5.7.43-linux-glibc2.12-x86_64 /usr/local/mysql
3,# 更改所属的组和用户
cd /usr/local
[root@CDH-141 local]# chown -R mysql mysql/
[root@CDH-141 local]# chgrp -R mysql mysql/
[root@CDH-141 local]# cd mysql/ [root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]# chown -R mysql:mysql data
mkdir /var/lib/mysql
chown -R mysql /var/lib/mysql
chgrp -R mysql /var/lib/mysql
4,在/etc下创建my.cnf文件
# 编辑my.cnf [root@CDH-141 mysql]# vim /etc/my.cnf [mysql] socket=/var/lib/mysql/mysql.sock # set mysql client default chararter default-character-set=utf8 [mysqld] socket=/var/lib/mysql/mysql.sock # set mysql server port port = 3323 #默认是3306 # set mysql install base dir basedir=/usr/local/mysql # set the data store dir datadir=/usr/local/mysql/data # set the number of allow max connnection max_connections=200 # set server charactre default encoding character-set-server=utf8 # the storage engine default-storage-engine=INNODB #忽略数据库表名的大小写 lower_case_table_names=1 #最大请求包 max_allowed_packet=16M explicit_defaults_for_timestamp=true sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION [mysql.server] user=mysql #用户不是mysql时,更改此处 basedir=/usr/local/mysql
5,安装mysql,设置mysql服务
# 安装mysql [root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld [root@CDH-141 mysql]# chown 777 /etc/my.cnf [root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld
6,启动mysql服务
# 启动mysql [root@CDH-141 mysql]# /etc/init.d/mysqld start/restart/stop/status 或者 [root@CDH-141 mysql]# service mysqld start/stop/restart/status
7,将mysql命令加入环境变量path中
vim ~/.bashrc
export PATH=$PATH:/usr/local/mysql/bin
export LD_LIBRARY_PATH=/usr/local/mysql/lib
保存退出
source ~/.bashrc
8, 获得mysql初始密码,运行mysql尝试登录
cat /root/.mysql_secret
mysql -pZb3JrNaTUg-a 如报错:
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
apt install -y libncurses*
9,修改密码
set PASSWORD = PASSWORD('123456');
10,添加远程访问权限
# 添加远程访问权限 mysql> use mysql # 修改root用户可以远程登录: mysql> update user set host='%' where user='root'; flush privileges; 或者 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root用户密码' WITH GRANT OPTION; 无需flush privileges; mysql> select host,user from user;
远程账号登录时,此时需要指定-P3323,因为之前我们创建的my.cnf文件中的端口为3323,如果改成默认的3306端口,并重启mysql服务后,可以不追加-P参数
mysql -uroot -proot用户密码 -h你的主机 -P3323
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。