mysql安装
mysql安装
1.centos7安装命令:
yum install -y mysql
yum install -y mysql-devel
yum install -y mariadb(安装mysql_server时会报错,可以安装这个插件解决)
2.ubuntu安装命令:
sudo apt-get install mysql-server
启动mysql服务
centos:systemctl start mysql / service mysql start
ubuntu:sudo /etc/init.d/mysql status(服务启动命令)/ service mysql start(系统服务启动命令)
查看mysql服务占用端口
ps -aux | grep mysql
netstat -nlt|grep xxx
mysql操作
1.用户登录mysql:
mysql -u root -p password
2.允许远程登录mysql
+修改mysql配置文件(方法1)
sudo vi /etc/mysql/my.cnf
#注释bind-address #bind-address = 127.0.0.1
重启mysql服务
+修改登录用户的权限(方法2)
mysql服务器中执行:grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
远程登录mysql:mysql -uroot -p<password> -h <host-id> -P<port>
3.数据库的查看/创建/删除操作
+show database;
-use mysql;
-show tables;
-desc xxxx;
+create table name(id int(16,name vchar(20)));
+drop table name;
+select xxx from table where id="xxxx";
4.给用户授予权限
-grant all on xxx.* to newuser@'%' identified by 'newuser';
5.更新用户密码
-mysql -uroot -p;
-use mysql;
-update user set password=password("newpassword") where user='root';
-flush privileges;(刷新权限)
centos6.5 安装mysql:
Step1: 检测系统是否自带安装mysql
# yum list installed | grep mysql
Step2: 删除系统自带的mysql及其依赖命令:
# yum -y remove mysql-libs.x86_64
Step3: 给CentOS添加rpm源,并且选择较新的源命令:
# wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# yum localinstall mysql-community-release-el6-5.noarch.rpm
# yum repolist all | grep mysql
# yum-config-manager --disable mysql55-community
# yum-config-manager --disable mysql56-community
# yum-config-manager --enable mysql57-community-dmr
# yum repolist enabled | grep mysql
Step4:安装mysql 服务器命令:
# yum install mysql-community-server
Step5: 启动mysql命令:
# service mysqld start