linux安装mysql

【操作步骤】

1、检查mysql是否安装

rpm -qa|grep mysql

2、下载mysql

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

3、解压

tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

4、移动到/usr/local/文件夹下

mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

5、新建data目录

mkdir /usr/local/mysql/data

6、新建用户

useradd mysql

passwd xxxx    输入密码

chown -R mysql:mysql /usr/local/mysql

chmod -R 777 /usr/local/mysql

6、检测链接库是否存在,并安装

rpm -qa|grep libaio

yum install libaio-devel.x86_64

6、编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)

cd /usr/local/mysql/bin

./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

7、编辑配置文件my.cnf

 vi /etc/my.cnf  

配置如下

[mysqld]datadir=/usr/local/mysql/data

port=3306

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

symbolic-links=0

max_connections=400

innodb_file_per_table=1

#表名大小写不明感,敏感为

lower_case_table_names=1

8、启动mysql

/usr/local/mysql/support-files/mysql.server start

9、添加软连接,并重启mysql服务

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

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

service mysql restart

10、登录mysql,修改密码(密码为之前生成的临时密码)

mysql -u root -p

set password for root@localhost=password('xxxxx');

11、开放远程连接(可选)

mysql>use mysql;

msyql>update user set user.Host='%' where user.User='root';

mysql>flush privileges;

12、设置开机自动启动

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

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --list


【问题解决】mysql登录报错:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object

service mysql stop

yum install libncurses*

service mysql start

mysql -u root -p 继续

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